0

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?

Matzi
  • 13,770
  • 4
  • 33
  • 50
user1625602
  • 63
  • 1
  • 6

2 Answers2

0

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.

Kai Mattern
  • 3,090
  • 2
  • 34
  • 37
0

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
megas
  • 21,401
  • 12
  • 79
  • 130