Reputation: 460
Need to have alternate route to create
must work both:
POST /users
POST /users/new
There recomendation from question how to add route without id:
resource :user do
get :me, on: :member
end
Need not user
but users
:
resources :users do
post :new, on: :create
end
crash message:
NameError: undefined local variable or method `on' for #<ActionDispatch::Routing::Mapper:0x0000081022c8c0\>
What is the solution?
Upvotes: 0
Views: 124
Reputation: 1322
Try
resources :users do
post :new, on: :collection
end
You need to specify the HTTP verb, action and the target. If the target is :member
, then Rails expects an "id" parameter and constructs the URL based on that.
Make sure to read this guide on Rails routes.
Upvotes: 1