为什么application_controller中的方法不可见?

时间:2010-12-08 02:51:24

标签: ruby-on-rails

在我的applicatin_controller.rb中,我添加了:

def test?
   true
end

我尝试在我的视图中使用它并且它不起作用

<%=测试? %GT;

错误:

undefined method

1 个答案:

答案 0 :(得分:2)

默认情况下,视图中无法访问控制器方法。 请尝试以下方法:

def test?
  true
end
helper_method :test?