I need to generate link like
tasks/new/1
but my link_to generates link like
<%= link_to "", {:controller => "tasks", :action => "new", :pid => project.id } %>
tasks/new?pid=1
What i need to do?
I need to generate link like
tasks/new/1
but my link_to generates link like
<%= link_to "", {:controller => "tasks", :action => "new", :pid => project.id } %>
tasks/new?pid=1
What i need to do?
A link to "tasks/new/1" actually would not be restful. New links never specify their id, as you cannot know the id to be given out by the database. By convention the id behind a ressource belongs to that ressource, not a relation.
The Restful way would be
/projects/1/tasks/new
You can achieve this via setting correct routing.
Have a look here: http://edgeguides.rubyonrails.org/routing.html
And search for the heading nested resources.
I assumed that you have nested resources projects and tasks.
<%= link_to 'New Task', new_project_task(project) %>
This link should create path /projects/1/tasks/new
The short form is
<%= link_to 'New Task', [:new, @project, :task] %>
The routes file should have
resources :projects do
resources :tasks
end