基本上我有一个UsersInitializeController类的ActionController :: RoutingError(未定义的方法`的before_filter”类):错误
class UsersInitializeController < ApplicationController
before_filter :authenticate_user!
def create
render true
end
end
的authenticate_user!在应用程序控制器中找到
class ApplicationController < ActionController::Base
# protect_from_forgery
def authenticate_user!
@current_user = User.find_by_token params[:auth_token]
if [email protected]_user
@current_user = User.create :token => params[:auth_token]
end
end
end
当我的应用程序启动时,它将POST请求发送到UsersInitializeController。由于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
###的问题解决了###
未使用的设计宝石以某种方式导致并发症。删除它并完成。
你可以发布整个异常堆栈吗?看看你在标题中使用的错误,我认为问题不在于你的authenticate_user方法。这是一个路由错误,未定义的方法是before_filter。 – 2012-03-06 08:12:40
我已按要求编辑! – 2012-03-06 08:36:27
很奇怪。它建议在加载Rails之前调用before_filter方法。如果将before_filter移动到应用程序控制器并执行相同的操作,会发生什么情况? – 2012-03-06 09:54:20