I’m confused about routing in rails. I have custom actions on a controller called UsersController, such as “login”.
In my routes.rb if I do:
resource :users do
collection do
get 'login'
post 'login'
get 'logout'
end
end
I can link to the action login of UsersController no problem but then going to localhost:3000/users gives me the error:
Couldn’t find User without an ID
But if I do
resources :users
localhost:3000/users gives me the expected listing.
I tried to put both but only the first version that is present in the file will work as expected.
How can I add routes to the default ones?
You have a typo in your routes.
Try
resourcesnotresource. (resourcedoesn’t create the #index action)Take a look to the manual