Rails update_attribute

I had the following problem. I have a model called a user that has an activated column. I am trying to update this value with the activated method ?, but it gives me an error: verification failed: password cannot be empty, password is too short (at least 6 characters). Which does not make sense to me, because I do not touch the password field! I just want to update the activated column. I put a code here that I think is appropriate, but if you think you need more, just ask :) Thank you so much in advance!

Model:

attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation, :activated
has_many :sucu_votes

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :name,  :presence => true,
                                    :length => { :maximum => 50 }

validates :email, :presence => true,
                                    :format => {:with => email_regex},
                                    :uniqueness => { :case_sensitive => false }

validates :password, :presence => true,
                                         :length => { :within => 6..15 },
                                         :confirmation => true

before_save :encrypt_password

def activated?
    self.update_attributes!(:activated => true)
    return self.activated
end

The controller from which the method is activated? called

def activate
if request.get?
        user=User.find_by_id(params[:id])
        if user.activated?
            flash[:notice]="Your account has been activated"
            #redirect_to :controller => 'sessions', :action => 'new'
        else
            flash[:error]="We couldnt activate the account"
            redirect_to :controller => 'sessions', :action => 'new'
        end
    end
end
+5
source share
1 answer

, - , . , , . -, update_attributes :

update_attribute(:activated, true)

+12

All Articles