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}"
}
end
link_to_remote_without_with_hash(text, args)
end
alias_method_chain :link_to_remote, :with_hash
end
Just thought I''d share it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---