I have two machines running my rails app. A linux machine and MAC OS X.
The issue I am having is that when I create a new user in my app, Devise's confirmable
method works just fine on one machine, but doesn't in another.
This is the error in the Linux machine:
Started GET "/users/login" for 72.252.205.36 at Sat Jun 18 18:00:35 -0500 2011
Processing by Devise::SessionsController#new as HTML
nil
Rendered devise/shared/_links.erb (1.9ms)
Rendered devise/sessions/new.html.erb within layouts/application (10.8ms)
Completed 200 OK in 90ms (Views: 18.3ms | ActiveRecord: 1.8ms)
Started GET "/users/confirmation?confirmation_token=12O-F_JMzI-SxpIEEEAh" for 72.252.205.36 at Sat Jun 18 18:02:04 -0500 2011
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"12O-F_JMzI-SxpIEEEAh"}
nil
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '12O-F_JMzI-SxpIEEEAh' LIMIT 1
Slug Load (0.2ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 3 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
AREL (0.2ms) UPDATE "开发者_如何学JAVAusers" SET "updated_at" = '2011-06-18 23:02:04.980588', "confirmed_at" = '2011-06-18 23:02:04.977060', "confirmation_token" = NULL WHERE "users"."id" = 3
AREL (0.3ms) UPDATE "users" SET "current_sign_in_ip" = '72.252.205.36', "last_sign_in_ip" = '72.252.205.36', "updated_at" = '2011-06-18 23:02:04.986283', "sign_in_count" = 1, "current_sign_in_at" = '2011-06-18 23:02:04.984989', "last_sign_in_at" = '2011-06-18 23:02:04.984989' WHERE "users"."id" = 3
Completed 500 Internal Server Error in 88ms
NoMethodError (undefined method `update_space' for #<Authorization::AnonymousUser:0xb611f240 @role_symbols=[:guest]>):
app/controllers/application_controller.rb:27:in `after_sign_in_path_for'
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (11.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.9ms)
But on OS X, this is what happens with the same action:
Started GET "/users/login" for 127.0.0.1 at 2011-06-18 18:02:49 -0500
Processing by Devise::SessionsController#new as HTML
nil
Rendered devise/shared/_links.erb (2.1ms)
Rendered devise/sessions/new.html.erb within layouts/application (38.2ms)
Completed 200 OK in 159ms (Views: 87.9ms | ActiveRecord: 269.9ms)
Started GET "/users/confirmation?confirmation_token=35eDT14LmVL5eusrsIRH" for 127.0.0.1 at 2011-06-18 18:03:12 -0500
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"35eDT14LmVL5eusrsIRH"}
nil
User Load (2.2ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '35eDT14LmVL5eusrsIRH' LIMIT 1
Slug Load (0.5ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 29 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
AREL (0.4ms) UPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2011-06-18 23:03:12.450907', "updated_at" = '2011-06-18 23:03:12.456550' WHERE "users"."id" = 29
AREL (0.4ms) UPDATE "users" SET "last_sign_in_at" = '2011-06-18 23:03:12.461899', "current_sign_in_at" = '2011-06-18 23:03:12.461899', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1', "sign_in_count" = 1, "updated_at" = '2011-06-18 23:03:12.462653' WHERE "users"."id" = 29
Redirected to http://localhost:3000/home/index
Completed 302 Found in 118ms
Here are the appropriate snippets of code.
From the Application_Controller.rb
def after_sign_in_path_for(resource)
Authorization.current_user.update_space
if resource.is_a?(User) && resource.has_trial_expired?
return url_for(:settings)
end
super
end
From the User.rb
:
def update_space
total_size = 0
if self.uploads.count > 0
self.uploads.each do |upload|
total_size += upload[:image_file_size]
end
end
self.space_used = total_size
self.save
end
So I have two questions:
- Why is it doing this ?
- How do I fix it ?
Thanks.
Updated: I am now getting this error in production on Heroku....except this is what the error looks like:
2011-07-01T21:24:22+00:00 app[web.1]: NoMethodError (undefined method `update_space' for #<Authorization::AnonymousUser:0x7f2d783cdcd0>):
2011-07-01T21:24:22+00:00 app[web.1]: app/controllers/application_controller.rb:27:in `after_sign_in_path_for'
精彩评论