Rails Rails3 Helper 默认全加载

cxh116 · August 17, 2012 · Last by hooopo replied at August 31, 2012 · 2915 hits

http://stackoverflow.com/questions/1179865/why-are-all-rails-helpers-available-to-all-views-all-the-time-is-there-a-way-t

helper 目录,与控制器不同名 helper,也会被加载的

因为加载顺序和命名冲突问题,引发了一个小 BUG...

擦,这样很容易命名冲突的。不知为啥默认都加载。

以前不是这样的....!

什么时候变成这样了?

命名带上 model 有关的就好了,比如:

user_name_tag
post_title_tag

加载顺序的问题你不要在 A Helper 里面调用 B Helper 的功能,或者倒过来也不要,然后就不会有问题了

靠,居然这么多人都不知道。。这样用感觉挺方便,注意下命名就 OK

#5 楼 @huacnlee 出现加载顺序的问题是因为有两个公有 Helper 里有方法名相同,以为是调用 helper 方法手动加载,所以才是出现这个情况的 #6 楼 @jjym 嗯 主要还是要注意一下命名

config.generators do |g| g.helper false end

只用 application_helper.rb 一个文件的路过

config.action_controller.include_all_helpers = false

You need to Sign in before reply, if you don't have an account, please Sign up first.