我在Rails中编写了一个应用程序,它正在快速增长,并且我正在学习它.但是我不了解助手.
application_helper.rb
module ApplicationHelper # This file it's empty end
users_helper.rb
module UsersHelper def avatar # Do something end end
customer_helper.rb
module CustomerHelper # This file it's empty end
为什么在任何客户的视图中都可以在用户帮助模块上调用头像辅助方法?
那么,为什么在许多文件中分离助手呢?
提前致谢.
P.S:Rails的第4版.
解决方法
因为默认情况下所有控制器都包含在所有控制器中.在这种情况下,单独的文件实际上仅用于逻辑分离.您可以改变该行为:
By default,each controller will include all helpers.
In prevIoUs versions of Rails the controller will include a helper
whose name matches that of the controller,e.g.,MyController will
automatically include MyHelper. To return old behavior setconfig.action_controller.include_all_helpers
tofalse
.
http://api.rubyonrails.org/classes/ActionController/Helpers.html