From 16a763517039bd9aa17530d8cc72962161a909a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 May 2009 17:34:15 -0700 Subject: [PATCH] Added an :escape_url option to remote_function --- .../lib/action_view/helpers/prototype_helper.rb | 18 +++++++++++++++++- actionpack/test/template/prototype_helper_test.rb | 2 ++ 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 1fbe012..4120a62 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -242,6 +242,18 @@ module ActionView # # :with => "'name=' + $('name').value" # + # :escape_url:: When set to false, the url is not javascript + # escaped. This allows one to include javascript + # in the url. Because the url is part of a javascript + # function call itself, any javascript must be inside + # single quotes. + # + # Example: + # + # :url => "/messages/' + (element.id.split('_').last()) + '.js", + # :escape_url => false + # + # # You can generate a link that uses AJAX in the general case, while # degrading gracefully to plain link behavior in the absence of # JavaScript by setting html_options[:href] to an alternate URL. @@ -446,6 +458,7 @@ module ActionView # # def remote_function(options) + escape_url = options.delete(:escape_url) javascript_options = options_for_ajax(options) update = '' @@ -464,7 +477,10 @@ module ActionView url_options = options[:url] url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash) - function << "'#{escape_javascript(url_for(url_options))}'" + url = url_for(url_options) + function << (escape_url == false ? + "'#{url}'" : + "'#{escape_javascript(url)}'") function << ", #{javascript_options})" function = "#{options[:before]}; #{function}" if options[:before] diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 28851f1..1cc82db 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -92,6 +92,8 @@ class PrototypeHelperTest < PrototypeHelperBaseTest def test_link_to_remote_url_quote_escaping assert_dom_equal %(Remote), link_to_remote("Remote", { :url => { :action => "whatnot's" } }) + assert_dom_equal %(Remote), + link_to_remote("Remote", { :url => { :action => "whatnot's" }, :escape_url => false }) end def test_button_to_remote -- 1.6.2.2.1669.g7eaf8