Rails 控制器的 Ruby 辅助方法放在哪里? [英] Where to put Ruby helper methods for Rails controllers?
本文介绍了Rails 控制器的 Ruby 辅助方法放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有某些(或所有)控制器需要的 Ruby 方法.我尝试将它们放在 /app/helpers/application_helper.rb
中.我已经将它用于要在视图中使用的方法.但是控制器看不到这些方法.是否还有其他地方应该放置它们,或者我是否需要以不同的方式访问这些辅助方法?
I have some Ruby methods certain (or all) controllers need. I tried putting them in /app/helpers/application_helper.rb
. I've used that for methods to be used in views. But controllers don't see those methods. Is there another place I should put them or do I need to access those helper methods differently?
使用最新的稳定 Rails.
Using latest stable Rails.
推荐答案
你应该在ApplicationController
中定义方法.
这篇关于Rails 控制器的 Ruby 辅助方法放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文