11175
(-- --)
June 30, 2008, 7:20am
1
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.
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?
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
11175
(-- --)
June 30, 2008, 10:32am
3
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!
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
11175
(-- --)
June 30, 2008, 10:50am
5
...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.
...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
11175
(-- --)
June 30, 2008, 12:11pm
7
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
11175
(-- --)
June 30, 2008, 8:12pm
8
Thanks guys. Looks clear now.
Cheers.