I’m trying to post to my registration controller using a link_to link.
I have <%= link_to "Register for Period", registration_path(period_id: period.id), :method => :post %>
Which generates a link like: http://localhost:3000/registrations/6?period_id=25 where the 6 is the event_id. I need to save the period_id and the user_id to the registration database.
I get the following error in the browser: No route matches [POST] "/registrations/6"
What am I doing wrong?
routes:
Mavens::Application.routes.draw do
devise_for :users
resources :events
resources :periods
resources :products
resources :cart_rows
resources :product_requests
resources :inqueries
resources :registrations
match '/profile', to: 'static_pages#profile'
root :to => 'static_pages#home'
get "static_pages/home"
get "static_pages/about"
end
If you put in your
routes.rb:And in your link:
You will have a route that matches your resquest.
When you only have a
resources :registrationsrule on yourroutes.rb, only the default restful routes are created, and there is noPOSTto a single resource created by default.I believe you will have to read something about the CSRF token, because if you have a
protect_from_forgeryon yourapplication_controller, probably thisPOSTrequest from a single link would not work.