简体   繁体   中英

Routing to a special controller action

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"):

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM