Rails 3 - How to send data on link_to :remote=>true?

Mr_Nizzle picture Mr_Nizzle · May 3, 2011 · Viewed 12.3k times · Source

I am trying to figure out the new link_to in Rails 3 but i still don't get it In Rails 2 I do:

<%= link_to_remote "My Link",:url=>{:action=>:myaction},:with=>"'data='+$('#someField').attr('value')" %>

but with the new syntax in Rails 3 how should it be?

I'm trying something like

<%=link_to "My Link",{:action=>"myaction"},:with=>"'data='+$('#someField').attr('value');",:remote=>true%>

but I'm not getting the quantity params in the controller's action

Answer

Vijay Dev picture Vijay Dev · May 3, 2011

Something like this will send a "data" parameter with the value = 10.

link_to "My Link", { :controller => 'myctrler', :action=>"myact", :data=> 10 }, :remote=>true

I've never seen/used the :with option before. I'm sorry I can't help on that one.