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 中声明的方法在所有控制器的范围内?

4

1 回答 1

2

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

before_filter :some_method
于 2014-05-30T17:54:51.227 回答