ruby-on-rails - ActionController::RoutingError(类的未定义方法 `before_filter'):错误

标签 ruby-on-rails ruby ruby-on-rails-3

基本上我有一个 UsersInitializeController 类

class UsersInitializeController < ApplicationController
  before_filter :authenticate_user!

  def create
    render true
  end
end

验证用户!在应用程序 Controller 中找到

class ApplicationController < ActionController::Base
  # protect_from_forgery

  def authenticate_user!
    @current_user = User.find_by_token params[:auth_token]
    if !@current_user
      @current_user = User.create :token => params[:auth_token]
    end
  end

end

当我的应用程序启动时,它向 UsersInitializeController 发送 POST 请求。由于设置了 before_filter,因此它将调用 authenticate_user!第一的。但是我得到的错误是 before_filter 是一个未定义的方法。

据我所知,before_filter 存在于 ActionController 中,并且由于 UsersInitializeContoller < ApplicationController < ActionController,我不应该收到此错误。以前有人遇到过这个问题吗?

异常堆栈(按要求)

Started POST "/users_initialize.json" for 127.0.0.1 at 2012-03-06 00:32:50 -0800

ActionController::RoutingError (undefined method `before_filter' for UsersInitializeController:Class):
app/controllers/users_initialize_controller.rb:3:in `<class:UsersInitializeController>'
app/controllers/users_initialize_controller.rb:1:in `<top (required)>'

Routes.rb 文件(按要求)

MyApplication::Application.routes.draw do
 resources :users_initialize
 match 'info/required_client_version' => 'info#required_client_version'
end

### 问题已解决###

未使用的 Devise Gem 不知何故导致了并发症。删除它并完成。

最佳答案

在“包含的 do” block 中添加 before_filter:

included do
    before_filter :authenticate_user!
end

更新: 刚注意到你已经解决了。但是我遇到了同样的麻烦,上面的解决方案解决了我的问题。所以,我会在这里留下评论,因为它可能会帮助其他人

关于ruby-on-rails - ActionController::RoutingError(类的未定义方法 `before_filter'):错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579865/

相关文章:

java - 将 MD5 messageDigest 从 Java 转换为 Digest::MD5 Ruby

ruby-on-rails - 如何找出我的系统上安装的 gem 的分支/原始版本?

javascript - 悬停链接时创建弹出窗口,就像在 facebook 中将光标放在链接上时一样,它会显示发送消息等选项

ruby-on-rails - 如何在 elastic-beanstalk 中应用 ruby​​ 版本补丁

css - 允许在多个 Rails 应用程序上自定义主题

Ruby:常量查找在 instance_eval/class_eval 中如何工作?

html - 计算 CSS 类的出现次数

ruby-on-rails - Rails 面板问题

mysql - 不确定如何将 SQL 转换为 Rails ActiveRecord

ruby-on-rails - Rails 3.1 has_many through - 反复出现的噩梦