方法
實例公開的方法
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() 連結
提供一個代理程式,讓視圖以外的程式可以存取輔助程式方法。
請注意,此代理程式是以不同的視圖內容渲染。這會造成捕捉方法的行為不正確。建議使用 helper 取代,在使用 capture
時。
來源:顯示 | 在 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
- 輔助程式的清單
回傳
-
陣列
- 提供的輔助程式清單的正規化模組清單。
來源:顯示 | 在 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