如何使用Rails访问控制器内的辅助方法

时间:2011-07-09 20:50:00

标签: ruby-on-rails methods controller helper viewcontext

我想在我的控制器内使用我的帮助器中的方法。 我不知道如何使用我听过的view_context可以做到这一点

2 个答案:

答案 0 :(得分:3)

正如apneadiving所说,将其作为一种控制器方法并使其成为一种辅助方法。

application_controller.rb

  helper_method :do_stuff

  def do_stuff
    #this method is available in all controllers and views

答案 1 :(得分:0)

我投票赞成@ apneadiving的想法。但是这里有:

class SomeController < ApplicationController
  include SomeHelper
end