从帮助文件调用方法

时间:2014-05-30 17:21:58

标签: ruby-on-rails ruby-on-rails-4 ruby-on-rails-4.1

在我的application_helper.rb中,我有以下内容:

def some_method
  do something
end

在我的application_controller.rb中,我有以下内容:

class ApplicationController < ActionController::Base
  include ApplicationHelper
  protect_from_forgery with: :exception
  require 'json'
  require 'csv'
end

在我的data_uploads_controller.rb中,我有以下内容:

class DataUploadsController < ApplicationController

  before_filter :authenticate_user!
  before_action :set_data_upload, only: [:show, :destroy]
  include DataUploadsHelper
  before_filter some_method

但是,我收到错误消息:

undefined local variable or method `some_method' for DataUploadsController:Class\

在application_controller中包含ApplicationHelper意味着ApplicationHelper中声明的方法是否在所有控制器的范围内?

1 个答案:

答案 0 :(得分:2)

您必须将该方法作为符号传递:

before_filter :some_method