aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-03-23 21:57:42 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2017-04-16 16:26:05 +0200
commita4c1282854795d1f0d7696ce1ccbabf94b3d9098 (patch)
tree5cdc43670a331fb1195f2f4ff929ff5dce42e554
parent6309b85100dd2b55c716ee4a4e9cbd3da2dc0617 (diff)
downloadrails-a4c1282854795d1f0d7696ce1ccbabf94b3d9098.tar.gz
rails-a4c1282854795d1f0d7696ce1ccbabf94b3d9098.tar.bz2
rails-a4c1282854795d1f0d7696ce1ccbabf94b3d9098.zip
Add `form_with_generates_remote_forms` config.
Allows users to not have remote forms by default, since there's more JS harness, e.g. bundling rails-ujs, otherwise. Also don't skip creating defaults file anymore. Sprockets isn't the only new config.
-rw-r--r--actionview/lib/action_view/helpers/form_helper.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt3
-rw-r--r--railties/test/generators/app_generator_test.rb1
4 files changed, 7 insertions, 5 deletions
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb
index bd035458a0..3eafe0028e 100644
--- a/actionview/lib/action_view/helpers/form_helper.rb
+++ b/actionview/lib/action_view/helpers/form_helper.rb
@@ -474,6 +474,8 @@ module ActionView
end
private :apply_form_for_options!
+ mattr_accessor(:form_with_generates_remote_forms) { true }
+
# Creates a form tag based on mixing URLs, scopes, or models.
#
# # Using just a URL:
@@ -1503,7 +1505,7 @@ module ActionView
end
private
- def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: false,
+ def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: !form_with_generates_remote_forms,
skip_enforcing_utf8: false, **options)
html_options = options.slice(:id, :class, :multipart, :method, :data).merge(html)
html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted?
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 324843a5f5..f4717bb35b 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -403,9 +403,7 @@ module Rails
end
def delete_new_framework_defaults
- # Sprockets owns the only new default for 5.1: if it's disabled,
- # we don't want the file.
- unless options[:update] && !options[:skip_sprockets]
+ unless options[:update]
remove_file "config/initializers/new_framework_defaults_5_1.rb"
end
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt
index 5f5545c4c7..a0c7f44b60 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt
@@ -5,6 +5,9 @@
# Once upgraded flip defaults one by one to migrate to the new default.
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
+
+# Make `form_with` generate non-remote forms.
+Rails.application.config.action_view.form_with_generates_remote_forms = false
<%- unless options[:skip_sprockets] -%>
# Unknown asset fallback will return the path passed in when the given
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 7965bd68d0..d3e131db94 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -410,7 +410,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_no_match(/config\.assets\.js_compressor = :uglifier/, content)
assert_no_match(/config\.assets\.css_compressor = :sass/, content)
end
- assert_no_file "config/initializers/new_framework_defaults_5_1.rb"
end
def test_generator_if_skip_yarn_is_given