ruby on rails - How not to repeat this code in my models -
I have a piece of code in a model that sets the start date and end date according to the time of day The law is run.
We jump straight in the example of code:
#MODEL now = time.Now if now HHOW: = 17 & amp; Amp; Now.hour & lt; = 23 # night n = now + 1.day startd = time.local (now.yure, now.mmth, nowdays, date, 17, 00, 00) endd = time.local (n.yure, n.month, n .day, 8, 00, 00) Alicef Now Hor & gt; = 0 & amp; Amp; Now.hour & lt; = 7 # Morning N = now 1 9 Dedged startd = time.local (n.yure, nmn, n.ed., 8, 00, 00) ended = time.local (now.year, within a model (one or the other), i Trying to run the function inside a search.
> #MODEL (Similar or Other) Model.find (: All, Conditions = & Gt; ['created_at> =? And created_at & lt; =?', Startd, endd])
The problem is that I start using that function and end dates I'm doing a lot to set up, and I do not know that Where to keep it for yourself.
You can call it the lib
directory All rabbi files in RAILS_ROOT / lib are automatically loaded in one module.
Comments
Post a Comment