Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 600
Mr_Nizzle Avatar asked May 03 '11 15:05

Mr_Nizzle


2 Answers

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.

like image 185
Vijay Dev Avatar answered Sep 19 '22 20:09

Vijay Dev


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?

like image 36
Mr_Nizzle Avatar answered Sep 23 '22 20:09

Mr_Nizzle