ruby-on-rails-4 – Rails中的助手4

我在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 set
config.action_controller.include_all_helpers to false.

http://api.rubyonrails.org/classes/ActionController/Helpers.html

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...