【发布时间】:2019-05-21 08:30:40
【问题描述】:
我了解 Rails 中有两种 label 方法(ActionView::Helpers::FormHelper#label 和 ActionView::Helpers::FormBuilder#label)。在rails console 中键入以下内容时,将调用哪个#label 方法:
$ rails c
Loading development environment (Rails 5.0.7.2)
2.6.0 :001 > helper.label(:post, :title, "A short title", class: "title_label")
=> "<label class=\"title_label\" for=\"post_title\">A short title</label>"
我已经进入 gems/actionview-5.0.7.2/lib/action_view/helpers/form_helper.rb 并注释掉了两个 label 方法,如下所示:
# def label(object_name, method, content_or_options = nil, options = nil, &block)
# Tags::Label.new(object_name, method, self, content_or_options, options).render(&block)
# end
.
.
.
# def label(method, text = nil, options = {}, &block)
# @template.label(@object_name, method, text, objectify_options(options), &block)
# end
但它仍在 Rails 控制台中执行label 方法,如何确定该方法调用的源位置?
【问题讨论】:
标签: ruby-on-rails erb rails-console