|
7 | 7 | require "action_view/helpers/active_model_helper"
|
8 | 8 | require "action_view/model_naming"
|
9 | 9 | require "action_view/record_identifier"
|
| 10 | +require "active_support/code_generator" |
10 | 11 | require "active_support/core_ext/module/attribute_accessors"
|
11 | 12 | require "active_support/core_ext/hash/slice"
|
12 | 13 | require "active_support/core_ext/string/output_safety"
|
@@ -2014,16 +2015,20 @@ def field_name(method, *methods, multiple: false, index: @options[:index])
|
2014 | 2015 | #
|
2015 | 2016 | # Please refer to the documentation of the base helper for details.
|
2016 | 2017 |
|
2017 |
| - (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector| |
2018 |
| - class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 |
2019 |
| - def #{selector}(method, options = {}) # def text_field(method, options = {}) |
2020 |
| - @template.public_send( # @template.public_send( |
2021 |
| - #{selector.inspect}, # :text_field, |
2022 |
| - @object_name, # @object_name, |
2023 |
| - method, # method, |
2024 |
| - objectify_options(options)) # objectify_options(options)) |
2025 |
| - end # end |
2026 |
| - RUBY_EVAL |
| 2018 | + ActiveSupport::CodeGenerator.batch(self, __FILE__, __LINE__) do |code_generator| |
| 2019 | + (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector| |
| 2020 | + code_generator.define_cached_method(selector, namespace: :form_builder) do |batch| |
| 2021 | + batch.push <<-RUBY_EVAL |
| 2022 | + def #{selector}(method, options = {}) # def text_field(method, options = {}) |
| 2023 | + @template.public_send( # @template.public_send( |
| 2024 | + #{selector.inspect}, # :text_field, |
| 2025 | + @object_name, # @object_name, |
| 2026 | + method, # method, |
| 2027 | + objectify_options(options)) # objectify_options(options)) |
| 2028 | + end # end |
| 2029 | + RUBY_EVAL |
| 2030 | + end |
| 2031 | + end |
2027 | 2032 | end
|
2028 | 2033 |
|
2029 | 2034 | # Creates a scope around a specific model object like form_for, but
|
|
0 commit comments