Hi. I have to use one of my method only once after data will be saved. So I thought that i will use callback with condition e.g ''if only_once?'' Therefore i nead a variable that will remember state whole time but i need to change it once. So should I use constant or class variable ? Or maybe is better way to do this ? Thanks for the replies in advance. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 29 March 2011 20:28, Bartek Iwaszkiewicz <bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi. > > I have to use one of my method only once after data will be saved. > So I thought that i will use callback with condition e.g ''if only_once?'' > Therefore i nead a variable that will remember state whole time but i need > to > change it once. > So should I use constant or class variable ? > Or maybe is better way to do this ?What do you mean when you say that you want to call this method only once? Do you mean only once ever in the life of the universe, after saving the very first record? In which case neither a class variable or a constant will do as these will get reset if the server is restarted. You will have to save a flag in the database to achieve this. Alternatively do you mean to call this method once for each *record* in the database when that record is first saved? in which case you can just call it after a new record is saved. Colin> > Thanks for the replies in advance. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Mar 29, 2011 at 1:28 PM, Bartek Iwaszkiewicz < bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi. > > I have to use one of my method only once after data will be saved. > So I thought that i will use callback with condition e.g ''if only_once?'' > Therefore i nead a variable that will remember state whole time but i need > to > change it once. > So should I use constant or class variable ? > Or maybe is better way to do this ? > > Thanks for the replies in advance. >Not sure what it is you are trying to save (if you give more detail you might get better answers), but if you are talking about something that is once in the lifetime of the app or server boot, you might just want to save it to the db or a fixed file somewhere. Of course if you know what the value is upfront you should use a constant. Also if it is environmentally dependent you could use the config/environments files for a constant.> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.