Mr_Nizzle
Mr_Nizzle

Reputation: 6714

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

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

Upvotes: 5

Views: 12558

Answers (3)

rome3ro
rome3ro

Reputation: 129

you just need to add the variable with the value in the path url, for example:

<%= link_to "SEND DATA", "server_function?myData=10", remote: true %>

and if you need to send more than one parameter you must to use & for example ?myData=10&myOtherData=12, where the params are myData with the value of 10 and myOtherData with 12.

Upvotes: 0

Mr_Nizzle
Mr_Nizzle

Reputation: 6714

They say its no longer supported in this answer on How to send Javascript Variable to a controller's action with the link_to helper?

Upvotes: 2

Vijay Dev
Vijay Dev

Reputation: 27486

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.

Upvotes: 5

Related Questions