Skip to content

Commit

Permalink
Merge pull request rails#28829 from y-yagi/follow_up_128b804
Browse files Browse the repository at this point in the history
Set to `form_with_generates_remote_forms` only when config is explicitly specified
  • Loading branch information
rafaelfranca authored Apr 22, 2017
2 parents 0541a0d + 87d6cb3 commit a6a93f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionview/lib/action_view/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class Railtie < Rails::Engine # :nodoc:

initializer "action_view.form_with_generates_remote_forms" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::FormHelper.form_with_generates_remote_forms =
app.config.action_view.delete(:form_with_generates_remote_forms)
form_with_generates_remote_forms = app.config.action_view.delete(:form_with_generates_remote_forms)
unless form_with_generates_remote_forms.nil?
ActionView::Helpers::FormHelper.form_with_generates_remote_forms = form_with_generates_remote_forms
end
end
end

Expand Down
28 changes: 28 additions & 0 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,34 @@ def index
assert_no_match(/data-remote/, last_response.body)
end

test "form_with generates remote forms by default" do
app_file "app/models/post.rb", <<-RUBY
class Post
include ActiveModel::Model
attr_accessor :name
end
RUBY

app_file "app/controllers/posts_controller.rb", <<-RUBY
class PostsController < ApplicationController
def index
render inline: "<%= begin; form_with(model: Post.new) {|f| f.text_field(:name)}; rescue => e; e.to_s; end %>"
end
end
RUBY

add_to_config <<-RUBY
routes.prepend do
resources :posts
end
RUBY

app "development"

get "/posts"
assert_match(/data-remote/, last_response.body)
end

test "default method for update can be changed" do
app_file "app/models/post.rb", <<-RUBY
class Post
Expand Down

0 comments on commit a6a93f9

Please sign in to comment.