Rails3 – 如何为控制器和视图提供自定义帮助程序 [英] Rails3 – How do I make a custom Helper available to controllers And Views
本文介绍了Rails3 – 如何为控制器和视图提供自定义帮助程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定 app/helpers/url_helper.rb 中的自定义帮助文件
Given the custom helper file in app/helpers/url_helper.rb
module UrlHelper
...
end
如何使其在所有控制器和所有视图中都可以访问?
How do I make it accessible in all controllers and in all views?
推荐答案
将其放入 ApplicationController(不是助手)并声明 helper_method :method_name
.
Place it in ApplicationController (not a helper) and declare helper_method :method_name
.
这篇关于Rails3 – 如何为控制器和视图提供自定义帮助程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文