ruby-on-rails - 在 Rails 控制台中使用辅助方法时确定 Rails 中标签方法的源位置
问题描述
我知道 Rails 中有两种label
方法 (ActionView::Helpers::FormHelper#label
和ActionView::Helpers::FormBuilder#label
) 可用。在以下内容中键入以下内容时将调用哪个#label
方法rails console
:
$ 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
但它仍在label
Rails 控制台中执行该方法,我如何确定该方法调用的源位置?
解决方案
这是第一个。第二个需要一个FormBuilder
对象(f.
部分)才能工作。
注释掉这些方法后,您是否重新加载了控制台?
我您正在使用Pry,您可以使用show-method
:
pry(main)> show-method helper.label
From: /home/user/.rvm/gems/ruby-2.5.3@gemset/gems/actionview-5.2.3/lib/action_view/helpers/form_helper.rb @ line 1114:
Owner: ActionView::Helpers::FormHelper
Visibility: public
Number of lines: 3
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
推荐阅读
- python - 对于 float64,Python 值太大
- python - 从 rgb 代码中查找颜色名称的可靠方法
- excel - 写入磁盘时,连接多个 excel 文件的 Pythons 脚本内存不足
- javascript - 实例函数?一种确定函数是否已在库内创建的方法
- enums - 如何通过 mono cecil 修改枚举类型
- rust - 如何从期货 0.1 组合方法链中提前返回?
- android - Android Edittext 不能专注于 API 22(代码在 API 23 及更高版本上运行良好)
- javascript - 在fusionauth中创建主题时出错
- vue.js - 我只能将 v-model 与 Vue.js 同步吗?
- android - Android Studio 在红线中抱怨“无法访问 androidx.activity.ComponentActivity”,但编译正常