ruby on rails - Devise and User.create -


usually when create model, user, attributes match database fields. example, if corresponding database table users_development has fields name , score when create instance of user class type user = user.create(:name => "myname", :score => 85).

now, devise created migration file including fields email , encrypted_password, cannot see field password (which quite logically security point of view).

while looking through forum posts saw many examples user.create(:email =>"me@domain.com", :password => "foo"). so, did password come from? not field of table users_development. going on behind scene? looked through documentation on http://rubydoc.info/github/plataformatec/devise/master/devise couldn't find explanation.

user.create(:email => "me@domain.com", :password => "foo") not directly create database record exact fields. rather, uses public_send("#{k}=", v) each pair in parameters hash. really, it's doing internally:

user = user.new user.email = "me@domain.com" user.password = "foo" user.save 

even though don't have password database field, devise's databaseauthenticatable module adds password= method, updates encrypted_password field:

def password=(new_password)   @password = new_password   self.encrypted_password = password_digest(@password) if @password.present? end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -