mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #17866 from bogdan/default-form-builder
Bugfix config.action_view.default_form_builder option
This commit is contained in:
commit
cd77755ae4
2 changed files with 42 additions and 1 deletions
|
@ -1935,6 +1935,8 @@ module ActionView
|
|||
end
|
||||
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
cattr_accessor(:default_form_builder) { ::ActionView::Helpers::FormBuilder }
|
||||
cattr_accessor(:default_form_builder, instance_writer: false, instance_reader: false) do
|
||||
::ActionView::Helpers::FormBuilder
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -494,6 +494,45 @@ module ApplicationTests
|
|||
assert last_response.body =~ /csrf\-param/
|
||||
end
|
||||
|
||||
test "default form builder specified as a string" do
|
||||
|
||||
app_file 'config/initializers/form_builder.rb', <<-RUBY
|
||||
class CustomFormBuilder < ActionView::Helpers::FormBuilder
|
||||
def text_field(attribute, *args)
|
||||
label(attribute) + super(attribute, *args)
|
||||
end
|
||||
end
|
||||
Rails.configuration.action_view.default_form_builder = "CustomFormBuilder"
|
||||
RUBY
|
||||
|
||||
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_for(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
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
get "/posts"
|
||||
assert_match(/label/, last_response.body)
|
||||
end
|
||||
|
||||
test "default method for update can be changed" do
|
||||
app_file 'app/models/post.rb', <<-RUBY
|
||||
class Post
|
||||
|
|
Loading…
Reference in a new issue