From 6caae0231c11ad89c1eeed3b0f8db8dfcb88c729 Mon Sep 17 00:00:00 2001 From: Riley Lynch Date: Sat, 6 Oct 2012 16:58:27 -0400 Subject: Accept :remote as symbol in link_to options Accept either :remote or 'remote' in both the html_options and (url_)options hash arguments to link_to. --- actionpack/CHANGELOG.md | 2 ++ actionpack/lib/action_view/helpers/url_helper.rb | 7 +++++-- actionpack/test/template/url_helper_test.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index be5180fec9..77010ecc70 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Accept :remote as symbolic option for `link_to` helper. *Riley Lynch* + * Warn when the `:locals` option is passed to `assert_template` outside of a view test case Fix #3415 diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 3f65791aa0..e8b3b14265 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -175,9 +175,10 @@ module ActionView def link_to(name = nil, options = nil, html_options = nil, &block) html_options, options = options, name if block_given? options ||= {} - url = url_for(options) html_options = convert_options_to_data_attributes(options, html_options) + + url = url_for(options) html_options['href'] ||= url content_tag(:a, name || url, html_options, &block) @@ -598,7 +599,9 @@ module ActionView end def link_to_remote_options?(options) - options.is_a?(Hash) && options.delete('remote') + if options.is_a?(Hash) + options.delete('remote') || options.delete(:remote) + end end def add_method_to_attributes!(html_options, method) diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 134177d74d..a969634e22 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -298,6 +298,20 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_link_to_with_symbolic_remote_in_non_html_options + assert_dom_equal( + "Hello", + link_to("Hello", hash_for(:remote => true), {}) + ) + end + + def test_link_to_with_string_remote_in_non_html_options + assert_dom_equal( + "Hello", + link_to("Hello", hash_for('remote' => true), {}) + ) + end + def test_link_tag_using_post_javascript assert_dom_equal( "Hello", -- cgit v1.2.3