I have confirmed that this method works. It basically takes email from the controller and modifies the email of a particular user.
However, it never saves data. I pass the wrong email format and returns false, if I pass the correct email method, returns true, which means that it assigned a new email and is called safe.
# Allows user to change email address def change_email(newmail) address = EmailVeracity::Address.new(newmail) if address.valid? self.email = newmail self.save return true else return false end end
I checked the logs first for any hints, but I get nothing:
Started POST "/members/editmail" for 127.0.0.1 at 2013-04-25 17:33:44 +0200 Processing by MembersController#editmail as HTML Parameters: {"authenticity_token"=>"*****=", "mail"=>"*****@gmail.com"} β[1mβ[35mUser Load (1.0ms)β[0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 β[1mβ[36mCharacter Load (0.0ms)β[0m β[1mSELECT `characters`.* FROM `characters` WHERE `characters`.`user_id` = 1β[0m β[1mβ[35m (0.0ms)β[0m BEGIN β[1mβ[36mUser Exists (0.0ms)β[0m β[1mSELECT 1 FROM `users` WHERE (`users`.`email` = BINARY '*****@gmail.com' AND `users`.`id` != 1) LIMIT 1β[0m β[1mβ[35mUser Exists (0.0ms)β[0m SELECT 1 FROM `users` WHERE (`users`.`username` = BINARY '******' AND `users`.`id` != 1) LIMIT 1 β[1mβ[36m (0.0ms)β[0m β[1mROLLBACKβ[0m Redirected to http://localhost:3000/members/1 Completed 302 Found in 10ms (ActiveRecord: 1.0ms)
It also makes sense to use a method to change this attribute. Since I use the Devise gem for authentication, I can use the current_user variable to retrieve the User object for the current user, and then just call current_user.email = newmail; current_user.save current_user.email = newmail; current_user.save in the controller.
source share