views:

728

answers:

2

i am wondering if the :with attribute is removed from rails3 since i cannot find anything in the rails3 api - http://rails3api.s3.amazonaws.com

anyone has a clue or give a hint on how to use the :with parameter to send data with a link_to

non-working example:

= link_to "Foo", {:action => "filter", :filter => "filter1",:with => "'test='+$('search').value"}, :remote => true, :class => "trash unselected", :id => "boo"

thanks!

+1  A: 

This goes against the point of non-obstrusive javascript and this is why it has been removed. Try looking at the railscast about the subject here: http://railscasts.com/episodes/205-unobtrusive-javascript

You should try another way of doing this.

marcgg
+1  A: 

There is though a way to work around it.

Use this in the view as a guideline:

link_to "Foo", {:action => "filter", :filter => "filter1"}, {:remote => true, :class => "trash unselected", :id => "boo", 'data-with' => "'&test='+$('search').value"}

(moved :with to the second part and made it 'data-with')

and add this to the bottom:

<script type="text/javascript" charset="utf-8">
  $$('a[data-remote=true]').each(function(a){
    a.onclick = function(){a.setAttribute('href', a.getAttribute('href') + eval(a.getAttribute('data-with')))};
  });
</script>

of course you will need to have prototype loaded (is in the default javascripts of a rails app)


For something a better than this one-liner: http://gist.github.com/451508

Using the gist you don't need to start :with with & or ?

vrinek