加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 02:46:50 所属栏目:百科 来源:网络整理
导读:我在Rails中编写了一个应用程序,它正在快速增长,并且我正在学习它.但是我不了解助手. application_helper.rb module ApplicationHelper # This file it's emptyend users_helper.rb module UsersHelper def avatar # Do something endend customer_helper.rb
我在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读