Big hole in my understanding of RoR

Thanks for digging into these details,

I have a similar situation, but I just hacked an rhtml to set defaults when creating the new objects. I quickly refactored after reading through this, but I'm left with a couple of questions.

First,

when I write...

def after_initialize    if self.new_record?      self.password ||= "password"    end end

I get blanks when render rhtml value @user.password.

However, if I write...

def after_initialize    if self.new_record?      self.password = "password" if self.password.blank?    end end

I get expected, pre-filled values in the view results. Curious why that would be the case. Is Rails evaluating the ||= differently? Is it defaulting the ruby behavior of evaluations?

Also, why is after_initialize recommended to overriding the constructor?

Both methods worked for me, although I did refactor from the overriding constructor to the after_initialize - I do like best practices.

Is it preferred due to the cloning issue?

Regards,

/ak

Wes Gamble schrieb: