Forum: Ruby on Rails getting old values

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.
Superbiji (Guest)
on 2006-02-17 10:55
(Received via mailing list)
Hi all,

I've add :before_update event to my model
Before updating a record I want to check if new attributes differ to old
attr.

My question is how to retrieve old attributes in :before_update event ?


thanks

--
gratis egold 1$ http://shegold.com/
unknown (Guest)
on 2006-02-17 11:29
(Received via mailing list)
Hello,

On Fri, Feb 17, 2006 at 03:53:06PM +0700, Superbiji wrote:
> My question is how to retrieve old attributes in :before_update event ?

I asked the same question some days ago. The answer was use the
database.
The database is made to be queried and queries are cached. So just do a
MyModel.find(foo.id).bar

Hope this helps!

Regards,

--
Damien MERENNE   <removed_email_address@domain.invalid>
http://www.cosinux.org/blogs/dam/

Chuck Norris doesn't churn butter.
He roundhouse kicks the cows and the butter comes straight out.
Superbiji (Guest)
on 2006-02-20 12:09
(Received via mailing list)
On 2/17/06, Damien MERENNE <removed_email_address@domain.invalid> wrote:
> Hello,
>
> I asked the same question some days ago. The answer was use the database.
> The database is made to be queried and queries are cached. So just do a
> MyModel.find(foo.id).bar

Thanks for your answer, I'll try that

I do different way,
by overiding all attributes with
def ATTRIBUTE=(value)
   @oldies[:attribute] = value
   self[:attribute] = value
end

but I hope "getting old values" should be ActiveRecord's standard
feature


--
jual beli gratis egold 1$ http://shegold.com/
Nic W. (Guest)
on 2006-02-20 20:13
(Received via mailing list)
What exactly are you checking for?

ActiveRecord already has built in validation for uniqueness, take a
look at validates_uniqueness_of (pg 274 of AWD)

class User < ActiveRecord::Base
  validates_uniqueness_of :name,
	                        :on => :save,
	                        :message => "is already being used"

And you can always call validate whenever you want, not just upon save.

On 2/20/06, Superbiji <removed_email_address@domain.invalid> wrote:
> by overiding all attributes with
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
- Nic
Superbiji (Guest)
on 2006-02-21 08:57
(Received via mailing list)
On 2/21/06, Nic W. <removed_email_address@domain.invalid> wrote:
> What exactly are you checking for?
>

I want to make sure ONE field is really modified before update.
for example, a record can't be modified if field status is not changed

--
Jual Beli Gratis egold 1$ http://shegold.com/
Alex Y. (Guest)
on 2006-02-21 14:23
(Received via mailing list)
Superbiji wrote:
> On 2/21/06, Nic W. <removed_email_address@domain.invalid> wrote:
>> What exactly are you checking for?
>>
>
> I want to make sure ONE field is really modified before update.
> for example, a record can't be modified if field status is not changed
Not to dispute your need for this, but what's the use case here?  Why
does it matter if an unchanged record is saved?
This topic is locked and can not be replied to.