I'm working on a project management web app and I have to pages for viewing projects. One is for viewing all the projects, and the other one is for management of of the project the user owns (i.e is administrator).
As it is now one can reach the overview page for projects by the use of 'projects_path' (/projects). However for the project management page I want to have another url, 'projects/manage', and it's here I need help.
I have tried the following:
routes.rb:
match "/projects/manage" => "projects#manage", :as => 'manage_projects'
view:
<%= link_to "Manage projects", manage_projects_path %>
Which raises the following error:
Couldn't find Project with id=manage
app/controllers/projects_controller.rb:62:in `show'
Why do it direct me to the action 'show' when I've explicitly set it to direct me to 'manage' (projects#manage)? Apparently it want an 'id', which shouldn't be the case here because I want to show all the projects (that the user owns), not a specific.
How can I solve this?
If you are performing the manage action on multiple projects it is better to write collection action in following way,
resources :projects do
collection do
get "manage"
end
end
This will provide you the route /projects/manage, will automatically match the route to manage action and every thing will be as per the REST conventions.