RileyE
RileyE

Reputation: 11074

Rails: before_save variable contents

I'm reading a guide about Rails and I came across this line in a Model class:

before_save { |user| user.email = email.downcase }

This is to make sure that the email address is lowercase before it hits the database (but you already know that, because you guys and gals are smart!).

However, why not just have this:

before_save { |user| user.email.downcase! }

Wouldn't that be simpler to execute, or am I missing something?

Upvotes: 3

Views: 1302

Answers (1)

Tigraine
Tigraine

Reputation: 23648

Both do the same.. it just comes down to taste.

Upvotes: 2

Related Questions