问题
I am trying to display a page to show all products by current user. Because of this, I have created a new page showall.html.erb under products view.
I have done the following:
ProductsController
def showall
@products = current_user.products
end
routes
resources :products do
get :showall
end
I am aware that because of the nested resources the URL Pattern became
/products/:product_id/showall(.:format)
How do I actually get rid of the product_id part to achieve /products/showall to have one special page to render all products by the current user.
回答1:
You should change your route definition as follows:
resources :products do
collection do
get :showall
end
end
Check corresponding documentation.
Hope that helps!
来源:https://stackoverflow.com/questions/29652146/modify-url-pattern-ruby-rails