diff options
author | thedarkone <thedarkone2@gmail.com> | 2010-09-27 17:43:27 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2010-09-27 17:46:00 +0200 |
commit | b127e0cac97886d9fcaaea7b91f88becd2fcff2c (patch) | |
tree | 734ad19bfe6faf0e1e272923b4ad94e90d53cd7a | |
parent | dcabc6c04301a44d875447e4f88534ca04a538d6 (diff) | |
download | rails-b127e0cac97886d9fcaaea7b91f88becd2fcff2c.tar.gz rails-b127e0cac97886d9fcaaea7b91f88becd2fcff2c.tar.bz2 rails-b127e0cac97886d9fcaaea7b91f88becd2fcff2c.zip |
Performance: refactor convert_options_to_data_attributes.
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 98ea75502f..1c3ca78d28 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -584,20 +584,24 @@ module ActionView private def convert_options_to_data_attributes(options, html_options) - html_options = {} if html_options.nil? - html_options = html_options.stringify_keys + if html_options.nil? + link_to_remote_options?(options) ? {'data-remote' => 'true'} : {} + else + html_options = html_options.stringify_keys + html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options) - if (options.is_a?(Hash) && options.key?('remote') && options.delete('remote')) || (html_options.is_a?(Hash) && html_options.key?('remote') && html_options.delete('remote')) - html_options['data-remote'] = 'true' - end + confirm = html_options.delete('confirm') + method = html_options.delete('method') + add_confirm_to_attributes!(html_options, confirm) if confirm + add_method_to_attributes!(html_options, method) if method - confirm = html_options.delete('confirm') - method = html_options.delete('method') - add_confirm_to_attributes!(html_options, confirm) if confirm - add_method_to_attributes!(html_options, method) if method + html_options + end + end - html_options + def link_to_remote_options?(options) + options.is_a?(Hash) && options.key?('remote') && options.delete('remote') end def add_confirm_to_attributes!(html_options, confirm) |