Hi,
I am handling some records that have expiration date. Records should
expire 30 days after its creation.
I could add the logic in the controller but I think that should/could be
done in the model.
How can I do that in the model?
Why is it better in the model than in the controller?
Thanks.
On 30 Jun 2008, at 08:20, comopasta Gr wrote:
How can I do that in the model?
def self.expire!
expirable = find :all, :conditions => [“created_at < ?”, 30.days.ago]
do something with expirable
end
Why is it better in the model than in the controller?
Because it’s none of your controller’s business.
Fred
Thank you Fred!
Excuse my ignorance but is the function called automatically?
I’ve seen the ! ending in some functions, I wonder what is the meaning
of it.
I have a couple of books on RoR, I think I need new ones already
covering more stuff right now 
Thanks!
On 30 Jun 2008, at 11:32, comopasta Gr wrote:
Thank you Fred!
Excuse my ignorance but is the function called automatically?
Nope
I’ve seen the ! ending in some functions, I wonder what is the meaning
of it.
Whatever meaning it has is usually a convention (eg on String methods
with a ! modify inplace, the ones without return a copy with that
modification (eg gsub and gsub!).
As far as ruby itself is concerned it makes no difference
Fred
…is the function called automatically?
Nope
Sorry again, so from where and by who should that function be called? A
cron job for example?
Thanks once again.
On 30 Jun 2008, at 11:50, comopasta Gr wrote:
…is the function called automatically?
Nope
Sorry again, so from where and by who should that function be
called? A
cron job for example?
For example. I didn’t say anything about that because I haven’t the
faintest clue when you want it called.
Fred
Thanks guys. Looks clear now.
Cheers.
expirable = find :all, :conditions => [“created_at < ?”, 30.days.ago]
do something with expirable
This u can write as a rake task and can be called it from cron
Sijo