comopasta Gr
2008-Jun-30 07:20 UTC
Setting expiration date based on creation date in model?
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-30 09:49 UTC
Re: Setting expiration date based on creation date in model?
On 30 Jun 2008, at 08:20, comopasta Gr wrote:> > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-Jun-30 10:32 UTC
Re: Setting expiration date based on creation date in model?
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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-30 10:44 UTC
Re: Setting expiration date based on creation date in model?
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> I have a couple of books on RoR, I think I need new ones already > covering more stuff right now ;-) > > Thanks! > > > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-Jun-30 10:50 UTC
Re: Setting expiration date based on creation date in model?
>> ...is the function called automatically? > > NopeSorry again, so from where and by who should that function be called? A cron job for example? Thanks once again. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-30 11:21 UTC
Re: Setting expiration date based on creation date in model?
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 once again. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sijo Kg
2008-Jun-30 12:11 UTC
Re: Setting expiration date based on creation date in model?
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-Jun-30 20:12 UTC
Re: Setting expiration date based on creation date in model?
Thanks guys. Looks clear now. Cheers. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---