Forum: Ruby on Rails Passing off values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Josh G. (Guest)
on 2007-01-27 08:25
How do you pass of values using link_to? Here is what I am trying:

<%= link_to "Comment On This Article", :action => "comment", :article =>
@article.id %>

And then on the next page I am trying to grab the :article value with:

<%= hidden_field_tag :article, params[:article] %>

Except that params[:article] is empty, telling me it didn't pass it off.
How can I fix this? Thanks.

Cheers,
- Josh
Bill W. (Guest)
on 2007-01-27 17:14
(Received via mailing list)
Hi Josh,

Josh G. wrote:

> Except that params[:article] is empty, telling me
> it didn't pass it off.

Params are the mechanism for passing values from a rendered page back to
the
controller.  Those values can then be used in the controller to do
whatever,
including using them in the construction / rendering of another page.
To do
that, you pass the value to the View in the form of an instance
variable.
Params: view --> controller.  Instance variables:  controller --> view.
So
in your case you'd need to do...

controller code:
def action
  @article = params[:article]
end

hth,
Bill
This topic is locked and can not be replied to.