Robert
Robert

Reputation: 1589

Grab value from textfield to use in link_to

I'm just starting out learning Rails and am trying to figure out how to grab a value from a text field and pass in a link_to. Please show how to add a textfield to form and pass its value in the following line. Thanks!!

<%= link_to('Show My Items 1',:controller => 'items', :action => 'myitems', :user_id => textbox_value) %>

Upvotes: 0

Views: 1924

Answers (1)

robmclarty
robmclarty

Reputation: 2245

I'm not totally sure where your values are coming from. If you want to copy the value of one dom element into another, you'd need to use javascript after Rails has rendered link_to.

If you have the value of user_id at the time Rails is rendering link_to (e.g., from a user model @user loaded in the controller) you could use its value (e.g., @user.id).

Other than that, you'd need to provide more details. You can find more information on how link_to works here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

Upvotes: 1

Related Questions