Passing off values

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

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs