ruby on rails - Before filter syntax difference -
what difference between these 2 clips of code? first clip labeled "this one:" , second clip labeled "and this:". (.rb)
class reseller < activerecord::base attr_accessible :blah, :blah, :contact_email
this one:
before_save { |reseller| reseller.contact_email = contact_email.downcase }
and this:
before_save { contact_email.downcase }
thank you
the first sets value back persisted property (or @ least should; i'd double check).
the second downcases , nothing result.
if second read contact_email.downcase!
should modify actual property.
the "bang" method follows ruby convention of naming destructive methods, e.g., methods alter underlying data, trailing !
.
note: tadman points out, you'd need vet against ar tests make sure app still functions expected, since may bypass of ar's magic.
Comments
Post a Comment