link_to_remote :with hash

I found myself doing a lot of long :with strings with link_to_remote
when passing multiple parameters from the page by dom ids. This
strings are really easy to mess up so I added a behavior to
link_to_remote that allows me to pass a hash to the :with parameter
like this ->

link_to_remote "click me",
  :url => {:action => 'some_action'},
  :with => {:parameter => :some_dom_id,
    :another_parameter => :another_dom_id,
    "a[hash][parameter]" => :dom_id_3}

I added this to environment.rb

ActionView::Helpers::PrototypeHelper.class_eval do
  def link_to_remote_with_with_hash(text, args)
    if Hash == args[:with].class
      args[:with] = "'" << args[:with].collect{|var, val|
          "#{var}=' + encodeURIComponent($('#{val}').value)"
        }.inject{|str, el|
          str << " + '&#{el}"
    link_to_remote_without_with_hash(text, args)
  alias_method_chain :link_to_remote, :with_hash

Just thought I'd share it.

Hi Julian,

That's interesting. You should do a write-up. Maybe on the wiki, or in a

Best regards,

julian wrote: