overiding to_param of a nested attribute

Posted by cbrulak on Stack Overflow See other posts from Stack Overflow or by cbrulak
Published on 2010-05-27T21:29:33Z Indexed on 2010/05/27 21:31 UTC
Read the original article Hit count: 175

Filed under:

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails