# Any programmer can answer this in 2 sec, but I'm stumped

**URL:** <https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397>\
**Category:** Rails\
**Created:** [July 26, 2007, 12:49am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397 "2007-07-26T00:49:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 26, 2007, 12:49am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397/1 "2007-07-26T00:49:37Z")

</div>

I’ve just started working with Rails. And I can’t figure out what  
seems to be the easiest thing imaginable. I need to send @ferry.id  
from a view in ferry\_controller…

\<%= link\_to ‘Add new schedule’, {:controller =\> ‘schedule’, :action =\>  
‘new’, ferry\_id =\> @ferry.id }%\>

to a method in schedule\_controller…

def new  
@schedule = Schedule.new  
end

and have that value survive into the ‘new’ view where it will be  
returned in Schedule.new(params[:schedule]).

How is this done? I’m must be utterly simple but I can’t figure it  
out.

Gavin

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 26, 2007, 12:55am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397/2 "2007-07-26T00:55:38Z")

</div>

On 7/25/07, Gavin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def new
> 
> >

Hey Gavin,

You can create an instance variable the same as you do with the  
schedule.  
@ferry\_id = params[:ferry\_id]

If the ferry\_id is part of the schedule, then you might want to create  
the Schedule object with the ferry id  
@schedule = Schedule.new :ferry\_id =\> params[:ferry\_id]

In either case you’ll need a hidden tag on the new page, so the param  
gets passed into the create action. If you do things the second way  
you just do  
\<%= f.hidden\_field :ferry\_id %\>

and it’ll be slurped up in params[:schedule]

Pat

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 26, 2007, 1:59am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397/3 "2007-07-26T01:59:33Z")

</div>

Hey Pat

Thanks for the quick reply. I’m still not sure how the @ferry\_id  
travels from my ferry\_controller’s view to the schedule\_controller.  
Is it something like this:

\<%= link\_to ‘Add new schedule’, {:controller =\> ‘schedule’, :action =\>  
‘new’, ferry\_id =\> @ferry.id }%\>

then this:

def new(\*args)  
@schedule = Schedule.new :ferry\_id =\> params[:ferry\_id]  
end

Something stills feels awkward about it.

Gavin

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 26, 2007, 2:09am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397/4 "2007-07-26T02:09:35Z")

</div>

That’s precisely it, except you’ll use :ferry\_id in the link\_to call of  
course.

How does it feel awkward to you?

Pat

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 26, 2007, 2:49am UTC](https://www.ruby-forum.com/t/any-programmer-can-answer-this-in-2-sec-but-im-stumped/110397/5 "2007-07-26T02:49:38Z")

</div>

Hey! It works!

I came from C# and .net and it seems to me that the syntax in Ruby and  
Rails is less clear. I’ve only been at it for a week  
though…probably just need more time to let it soak in.

Thanks for the help, Pat.

Gavin
