Rails 6 中是否必须手动将 ApplicationHelper 包含在 ApplicationController 中?

2024-04-19

控制器:

class FooController < ApplicationController
  def index
    bar_method

应用程序助手:

module ApplicationHelper
  def bar_method

查看索引页引发undefined method bar_method.

Does ApplicationHelper需要手动包含吗?

Rails 6.


您不需要包含辅助模块。和helpers(在 Rails 5+ 中),您可以访问辅助方法。尝试这个:

class FooController < ApplicationController
  def index
    helpers.bar_method
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails 6 中是否必须手动将 ApplicationHelper 包含在 ApplicationController 中? 的相关文章

随机推荐