# Question about link\_to helper

**URL:** <https://www.ruby-forum.com/t/question-about-link-to-helper/115404>\
**Category:** Rails\
**Created:** [September 24, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/question-about-link-to-helper/115404 "2007-09-24T23:06:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [September 24, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/question-about-link-to-helper/115404/1 "2007-09-24T23:06:34Z")

</div>

Hi all,

I was wondering if someone might be able to answer a question for me.  
I’m working on a re-design of a magazine site and have models for both  
issue and article. Every article needs to belong to an issue, I’ve  
already set up the has\_many/belongs\_to relationship in the models.

What I’d like to know is if I can pass the ID of an issue to the new  
action for the article so that I can use something like  
issue.articles.build when creating the new article so that it is  
already assigned to an issue?

Is that clear enough?

Thanks.

---

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [September 24, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/question-about-link-to-helper/115404/2 "2007-09-24T23:16:35Z")

</div>

Assuming that @issue is set to the current issue and the article  
controller is called article and the action is called new, this works:

\<%= link\_to ‘New Article’, :controller =\> ‘article’, :action =\> ‘new’,  
:issue\_id =\> @issue %\>

For issue id 6 this would generate "/article/new?issue\_id=6 "

skoppy wrote:

> already assigned to an issue?
> 
> Is that clear enough?
> 
> Thanks.
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [September 24, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/question-about-link-to-helper/115404/3 "2007-09-24T23:59:40Z")

</div>

if you are doing it restfully you could nest the resouces

Routes.rb:  
map.resources :issues do |issues|  
issues.resources :articles  
end

Then in your view you would do:  
link\_to new\_article\_path(@issue)

And finally in your controller define a before filter like this:  
before\_filter :get\_issue

def get\_issue  
@issue = Issue.find(params[:issue\_id]  
end

---

<div class="post-metadata">

**Author:** ![skoppy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@skoppy](https://www.ruby-forum.com/u/skoppy)\
**Post date:** [September 25, 2007, 12:51am UTC](https://www.ruby-forum.com/t/question-about-link-to-helper/115404/4 "2007-09-25T00:51:44Z")

</div>

Thanks for all the help guys. I haven’t tackled the whole restful  
thing yet Andrew but will keep your advice in mind for when I do.  
Thanks again.
