Rails staging environment says "undefined method" but the console shows that method fine
A开发者_运维百科nyone have this happen before? I just uploaded my app to a staging server that's identical to the production server. I try to log in, and I get the "Something went wrong" 500 page. The log tells me the error is in my SessionsController (using restful_authentication), with the specific error being NoMethodError (undefined method 'enabled?' for #<User:0xb6c5dbd4>):
. I load up a console for my staging environment and pull back the user in question... and the enabled method is defined (calling user.enabled?
returns the expected value, and not a no method error).
Anyone have any ideas? I've specified in Passenger that the RailsEnv should be staging; could it be that Passenger is not recognizing this? When I created my database and ran my migrations, I had to explicitly say RAILS_ENV=staging
, otherwise it was trying to load the development data and throwing an error because my development box connects through a different MySQL socket than staging|production.
The enabled method is defined on my users table and therefore the User model. The code in the controller is something like this:
# SessionsController.rb
def create
user = User.authenticate(params[:username], params[:password)
if user
unless user.enabled?
note_disabled_account # basically prints a message
else
self.current_user = user
# other stuff
redirect_back_or_default('/')
end
end
end
The code is identical in Production and works fine, so the issue is something related to the fact that I created a "staging" environment.
EDIT: I've narrowed the error down to being some kind of caching issue, despite the fact I've restarted Passenger. We are using Amazon EC2 and the staging server was basically cloned from Production (so it had an older version of the application on it). For some reason when I am deploying from Capistrano and restarting Passenger, it does not seem to properly link to the new version; I tried removing the enabled line and I was able to log in, but pulling up a record gives me another undefined method - the method in question is something that was added after the Staging server was created.
精彩评论