Link_to parameters

Hello,

I would like to have a link_to automatically populate a field in the
form that it is linking to.

For example (excuse my silly words, im trying to make a point)
<%= link_to “Add a COOL Post”, new_post_path, :howcoolisit => ‘COOL’
%>
<%= link_to “Add a NOTCOOL Post”, new_post_path, :howcoolisit =>
‘NOTCOOL’ %>

Then, I would have a field in that form:

<%= f.hidden_field :howcoolisit %>

And I would want it to be populated automatically (either NOTCOOL, or
COOL, depending on the link_to that the user has chosen.)

However, it is just being blank… nothing is getting populated. I must
be missing something, or my approach is wrong.

Does anyone know how to accomplish such a task? Thank you

–David Z.

David Z. wrote in post #972696:

Hello,

I would like to have a link_to automatically populate a field in the
form that it is linking to.

For example (excuse my silly words, im trying to make a point)
<%= link_to “Add a COOL Post”, new_post_path, :howcoolisit => ‘COOL’
%>
<%= link_to “Add a NOTCOOL Post”, new_post_path, :howcoolisit =>
‘NOTCOOL’ %>

Then, I would have a field in that form:

<%= f.hidden_field :howcoolisit %>

Are you reading the params[:howcoolisit] value and assigning it to @post
in the controller?

Are you reading the params[:howcoolisit] value and assigning it to @post
in the controller?

No I am not. How would I go about doing that? I don’t understand what
you mean by “reading the params[:howcoolisit] value”.

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