Forum: Ruby on Rails @new_record_before_save

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
TomRossi7 (Guest)
on 2009-05-12 22:27
(Received via mailing list)
Is there an easy way to access the ActiveRecord
@new_record_before_save attribute?

Thanks,
Tom
Philip H. (Guest)
on 2009-05-12 22:38
(Received via mailing list)
> Is there an easy way to access the ActiveRecord
> @new_record_before_save attribute?

Maybe...

 >> u = User.new
 >> u.new_record?
=> true
Rob B. (Guest)
on 2009-05-12 23:47
(Received via mailing list)
On May 12, 2009, at 2:26 PM, TomRossi7 wrote:

>
> Is there an easy way to access the ActiveRecord
> @new_record_before_save attribute?
>
> Thanks,
> Tom


Well, it depends on what you mean by easy.

model.instance_variable_get('@new_record_before_save') will work

If you're using an older ActiveRecord and you are trying to tell the
difference between a find_or_create_by_..., You can "rely" on the
deprecated model.new_record?.nil? to know that it was a find
(model.new_record? == false means it was actually a create)

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
This topic is locked and can not be replied to.