在哪里将Ruby helper方法用于Rails控制器? [英] Where to put Ruby helper methods for Rails controllers?

查看:104
本文介绍了在哪里将Ruby helper方法用于Rails控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有某些(或所有)控制器需要的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?

使用最新的稳定Rai​​ls.

Using latest stable Rails.

推荐答案

您应在ApplicationController中定义方法.

这篇关于在哪里将Ruby helper方法用于Rails控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆