diff options
5 files changed, 37 insertions, 12 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 7a9c2a3fa9..fd8b38054e 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* 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* + * Deprecate `button_to_function` and `link_to_function` helpers. We recommend the use of Unobtrusive JavaScript instead. For example: 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) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index a20a68c1b2..152b35ff0f 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2637,6 +2637,12 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_data_attributes + form_for(@post, data: { behavior: "stuff" }, remote: true) {} + assert_match %r|data-behavior="stuff"|, output_buffer + assert_match %r|data-remote="true"|, output_buffer + end + def test_fields_for_returns_block_result output = fields_for(Post.new) { |f| "fields" } assert_equal "fields", output diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 202f7e27c5..1ff307c735 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -85,16 +85,17 @@ module ActiveRecord assert @connection.active? original_connection_pid = @connection.query('select pg_backend_pid()') - # Fail with bad connection after next query attempt. - connection_class = class << @connection ; self ; end - connection_class.class_eval <<-CODE + # Fail with bad connection on next query attempt. + raw_connection = @connection.raw_connection + raw_connection_class = class << raw_connection ; self ; end + raw_connection_class.class_eval <<-CODE, __FILE__, __LINE__ + 1 def query_fake(*args) - if @called ||= false - @connection.stubs(:status).returns(PCconn::CONNECTION_BAD) + if !( @called ||= false ) + self.stubs(:status).returns(PGconn::CONNECTION_BAD) + @called = true raise PGError else - @called = true - @connection.unstub(:status) + self.unstub(:status) query_unfake(*args) end end @@ -107,13 +108,13 @@ module ActiveRecord @connection.verify! new_connection_pid = @connection.query('select pg_backend_pid()') ensure - connection_class.class_eval <<-CODE + raw_connection_class.class_eval <<-CODE alias query query_unfake undef query_fake CODE end - assert_equal original_connection_pid, new_connection_pid, "Should have a new underlying connection pid" + assert_not_equal original_connection_pid, new_connection_pid, "Should have a new underlying connection pid" end # Must have with_manual_interventions set to true for this diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 072aa8355d..2ffae66a57 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -20,9 +20,6 @@ # Generate digests for assets URLs. config.assets.digest = true - - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH <%- end -%> # Specifies the header that your server uses for sending files. |