0

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?

Community
  • 1
  • 1
fl-web
  • 462
  • 5
  • 16

1 Answers1

1

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.

gkats
  • 1,302
  • 9
  • 8