This project is archived and is in readonly mode.
remote_function does not allow dynamically generation of url
-
Jeroen van Dijk
I patched remote_function to solve my case while the default is still working. I have to figure out how to run the rails tests so I can add tests to it. In the mean while the following code calls /admin/mail_templates/:id.json because of the added options :escape_url
options = {} options[:url] = "/admin/mail_templates/' + value + '.json" options[:escape_url] = false options[:method] ||= :get options[:complete] ||= "process_mail_template(request)" observe_field(:mail_template_id, options)This is my patch
module ActionView class Base def remote_function(options) javascript_options = options_for_ajax(options) update = '' if options[:update] && options[:update].is_a?(Hash) update = [] update << "success:'#{options[:update][:success]}'" if options[:update][:success] update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure] update = '{' + update.join(',') + '}' elsif options[:update] update << "'#{options[:update]}'" end function = update.empty? ? "new Ajax.Request(" : "new Ajax.Updater(#{update}, " url_options = options[:url] url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash) function << (options[:escape_url] == false ? "'#{url_for(url_options)}'" : "'#{escape_javascript(url_for(url_options))}'") ## <-- I added this line function << ", #{javascript_options})" function = "#{options[:before]}; #{function}" if options[:before] function = "#{function}; #{options[:after]}" if options[:after] function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm] return function end end end -
anthony
I created the same ticket a few days ago and submitted a patch (almost identical to yours) before finding this ticket today. My ticket is number 2593: https://rails.lighthouseapp.com/...
The main diff in my patch (other than the fact that I updated the docs and added a unit test) is that I deleted the :escape_url parameter before passing the options to options_for_ajax so it doesn't end up in the params hash in the ajax function call.
Can we mark this as a dup and keep mine open as I've already generated the patch file?
-
Steve St. Martin
- Assigned user set to Ryan Bigg
duplicates #2593 Add an :escape_url option to remote_function, mark as duplicate
-
Ryan Bigg
- State changed from new to duplicate
Duplicate of #2593 Add an :escape_url option to remote_function.