Hi, I''m thinking about a method that responds true or false for the changes of attributes from a value to another to trace a little bit the status of an AR object. Ex. class Book < ActiveRecord::Base STATUS_DELIVER = [0,1] before_save :send_mail_to_customer def send_mail_to_customer UserMailer.send_mail_to_customer if self.changes[''status''] == [0, 1] end end It'' a simple case but when complexity grows up a method like def send_mail_to_customer UserMailer.send_mail_to_customer if self.status.changes(from: 0, to: 1) end Maybe is more mantenible and readable. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/IB6dNsqrq44J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I believe you can do this already with ActiveModel::Dirty<http://api.rubyonrails.org/classes/ActiveModel/Dirty.html> : def send_mail_to_customer UserMailer.send_mail_to_customer if status_change == [0, 1] end On Monday, December 17, 2012 9:14:33 AM UTC-5, angelo capilleri wrote:> > Hi, > I''m thinking about a method that responds true or false for the changes of > attributes from a value to another to trace a little bit the status of an > AR object. > > Ex. > class Book < ActiveRecord::Base > STATUS_DELIVER = [0,1] > before_save :send_mail_to_customer > > def send_mail_to_customer > UserMailer.send_mail_to_customer if self.changes[''status''] == [0, 1] > end > end > > It'' a simple case but when complexity grows up a method like > > def send_mail_to_customer > UserMailer.send_mail_to_customer if self.status.changes(from: 0, to: 1) > end > > Maybe is more mantenible and readable. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/xAAFpU6U2EoJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
This feature "from" and "to" was interesting, I extracted this to a gem https://github.com/YasuOza/activemodel-attribute_changed_specification/ I wish this gem makes your happy. On Tue, Dec 18, 2012 at 9:51 PM, Peter Brown <pete@lette.us> wrote:> I believe you can do this already with ActiveModel::Dirty: > > def send_mail_to_customer > UserMailer.send_mail_to_customer if status_change == [0, 1] > end > > > On Monday, December 17, 2012 9:14:33 AM UTC-5, angelo capilleri wrote: >> >> Hi, >> I''m thinking about a method that responds true or false for the changes of >> attributes from a value to another to trace a little bit the status of an AR >> object. >> >> Ex. >> class Book < ActiveRecord::Base >> STATUS_DELIVER = [0,1] >> before_save :send_mail_to_customer >> >> def send_mail_to_customer >> UserMailer.send_mail_to_customer if self.changes[''status''] == [0, 1] >> end >> end >> >> It'' a simple case but when complexity grows up a method like >> >> def send_mail_to_customer >> UserMailer.send_mail_to_customer if self.status.changes(from: 0, to: 1) >> end >> >> Maybe is more mantenible and readable. >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/xAAFpU6U2EoJ. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en.-- Yasuharu Ozaki E-mail : yasuharu.ozaki@gmail.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Very nice! We coult try to made a Pr to Rails... Il giorno mercoledì 19 dicembre 2012 02:32:59 UTC+1, Yasuharu Ozaki ha scritto:> > This feature "from" and "to" was interesting, I extracted this to a gem > > https://github.com/YasuOza/activemodel-attribute_changed_specification/ > > I wish this gem makes your happy. > > > On Tue, Dec 18, 2012 at 9:51 PM, Peter Brown <pe...@lette.us <javascript:>> > wrote: > > I believe you can do this already with ActiveModel::Dirty: > > > > def send_mail_to_customer > > UserMailer.send_mail_to_customer if status_change == [0, 1] > > end > > > > > > On Monday, December 17, 2012 9:14:33 AM UTC-5, angelo capilleri wrote: > >> > >> Hi, > >> I''m thinking about a method that responds true or false for the changes > of > >> attributes from a value to another to trace a little bit the status of > an AR > >> object. > >> > >> Ex. > >> class Book < ActiveRecord::Base > >> STATUS_DELIVER = [0,1] > >> before_save :send_mail_to_customer > >> > >> def send_mail_to_customer > >> UserMailer.send_mail_to_customer if self.changes[''status''] == [0, > 1] > >> end > >> end > >> > >> It'' a simple case but when complexity grows up a method like > >> > >> def send_mail_to_customer > >> UserMailer.send_mail_to_customer if self.status.changes(from: 0, to: > 1) > >> end > >> > >> Maybe is more mantenible and readable. > >> > > -- > > You received this message because you are subscribed to the Google > Groups > > "Ruby on Rails: Core" group. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/rubyonrails-core/-/xAAFpU6U2EoJ. > > > > To post to this group, send email to rubyonra...@googlegroups.com<javascript:>. > > > To unsubscribe from this group, send email to > > rubyonrails-co...@googlegroups.com <javascript:>. > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-core?hl=en. > > > > -- > Yasuharu Ozaki > E-mail : yasuhar...@gmail.com <javascript:> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/4VksCyU40cwJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.