cbrulak
cbrulak

Reputation: 15629

overiding to_param of a nested attribute

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

Answers (1)

shingara
shingara

Reputation: 46914

You need use the :anchor option

return project_url(project,:format => :html, :anchor => id)

Upvotes: 1

Related Questions