Reputation: 15629
I'm trying to create a perma link for a nested attribute.
For example, look at the links for the answers in SO. I would like to do something similar in rails:
I have Project
model with multiple tasks
and I would like to create a perma link to a task.
The task can only viewed with the project, just like Q & A on SO.
Ideally, i would do something like:
task_helper.rb:
def GetTaskURL
project = Project.find(:project_id)
return project_url(project,:html) + "#" + id
end
However, i get a method not found. So it seems the only way is to hard-code it:
domain.com url + Projects/show/id.html#task.id
Must be a better way?
Upvotes: 1
Views: 181
Reputation: 46914
You need use the :anchor option
return project_url(project,:format => :html, :anchor => id)
Upvotes: 1