方法
实例公共方法
helper_attr(*attrs) 链接
声明控制器属性的助手访问器。例如,以下代码向控制器添加了新的 name 和 name= 实例方法,并使其可用于视图:attr_accessor :name helper_attr :name
参数¶ ↑
-
attrs- 将转换为助手方法的属性名称。
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/helpers.rb, line 84 def helper_attr(*attrs) attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") } end
helpers() 链接
提供一个代理,用于从视图外部访问助手方法。
请注意,该代理在不同的视图上下文中渲染。这可能会导致 `capture` 方法出现不正确的行为。在使用 capture 时,请考虑改用 helper。
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/helpers.rb, line 94 def helpers @helper_proxy ||= begin proxy = ActionView::Base.empty proxy.config = config.inheritable_copy proxy.extend(_helpers) end end
modules_for_helpers(args) 链接
重写 modules_for_helpers 以接受 :all 作为参数,该参数会加载 `helpers_path` 中的所有助手。
参数¶ ↑
-
args- 助手列表
返回¶ ↑
-
array- 提供的助手列表的规范化模块列表。
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/helpers.rb, line 112 def modules_for_helpers(args) args += all_application_helpers if args.delete(:all) super(args) end