diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2012-08-08 16:35:59 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2012-08-08 16:36:46 -0500 |
commit | b540f4c1b812453d680724527635eddbffb980c4 (patch) | |
tree | 495e3c1465a476e39d7ed9799f066f02177958e1 /actionpack/lib/action_view | |
parent | c0954a4802028976d59f3fec645c5784e1572e82 (diff) | |
download | rails-b540f4c1b812453d680724527635eddbffb980c4.tar.gz rails-b540f4c1b812453d680724527635eddbffb980c4.tar.bz2 rails-b540f4c1b812453d680724527635eddbffb980c4.zip |
Allow data attributes to be set as a first-level option for form_for, so you can write `form_for @record, data: { behavior: 'autosave' }` instead of `form_for @record, html: { data: { behavior: 'autosave' } }` *DHH*
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 13a5671a17..5cfcfdd8d5 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -323,6 +323,24 @@ module ActionView # ... # </form> # + # === Setting HTML options + # + # You can set data attributes directly by passing in a data hash, but all other HTML options must be wrapped in + # the HTML key. Example: + # + # <%= form_for(@post, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %> + # ... + # <% end %> + # + # The HTML generated for this would be: + # + # <form action='http://www.example.com' method='post' data-behavior='autosave' name='go'> + # <div style='margin:0;padding:0;display:inline'> + # <input name='_method' type='hidden' value='put' /> + # </div> + # ... + # </form> + # # === Removing hidden model id's # # The form_for method automatically includes the model id as a hidden field in the form. @@ -409,6 +427,7 @@ module ActionView apply_form_for_options!(record, object, options) end + options[:html][:data] = options.delete(:data) if options.has_key?(:data) options[:html][:remote] = options.delete(:remote) if options.has_key?(:remote) options[:html][:method] = options.delete(:method) if options.has_key?(:method) options[:html][:authenticity_token] = options.delete(:authenticity_token) |