gpt4 book ai didi

ruby-on-rails - rails : Where to define a helper method that will be available to several controllers?

转载 作者:行者123 更新时间:2023-12-03 00:47:39 25 4
gpt4 key购买 nike

我想定义一个辅助方法 my_method,它将在 BuyersController 方法中可用(例如 indexcreate 等)。

我尝试在 app/helpers/application_helper.rb 中定义它,但它不起作用:

undefined method `my_method' for #<BuyersController:0x26df468>

它应该在某个共享的地方,因为我也想在其他 Controller 中使用它。这就是我尝试 app/helpers/application_helper.rb 的原因。

定义它的正确位置是什么?

最佳答案

它应该位于app/controllers/application_controller.rb

app/helpers/application_helper.rb 用于共享 View 助手。

关于ruby-on-rails - rails : Where to define a helper method that will be available to several controllers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4734367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com