I want to have a button to select a zip file, unzip, process one of those files and add the data to the database. I'm stuck at getting to the controller action.
bp_stats.controller
def import_data
puts "Massage and import data here"
end
routes.rb
get 'import_data', to: 'bp_stats#import_data'
The import button in _import_data.html.erb
:
<%= form_tag( action: :import_data, controller: 'bp_stats' ) do %>
<%= file_field_tag :filename %>
<%= submit_tag( "Import" ) %>
<% end %>
I'm getting this error
ActionController::RoutingError (No route matches [POST] "/import_data"):
CodePudding user response:
Your route says
get 'import_data', to: 'bp_stats#import_data'
which is clearly a get request route not a post request, you need to change this to a route for a post request using post
post 'import_data', to: 'bp_stats#import_data'