Reputation: 21039
I have a CRUD resource defined in my routes.rb file: resource :user
.
I'm adding a new controller method for the user called search_places
, which is performed on the user to find other users with the same place
s. I'm adding a route it.
Right now, I have:
post '/user/search_place'
, which isn't very DRY. I'm new to Rails and I was reading the Rails routing documentation and figured that I could possibly use
resource :user do
collection do
post 'search_place'
end
end
Is this considered good practice? I know this works (it passes my rspec route test), but is that how its best done?
Thank you,
Upvotes: 2
Views: 56
Reputation: 10137
When you add second don't need of first.
Add this:
resources :user do
collection do
post 'search_place'
end
end
Remove this:
resources :user
That makes DRY
:)
Suggestion: Resources name should be defined in plural if u follow rails convention. (i.e) resources :users
Upvotes: 1