Hi, Id like to do something like that: @payment_history = PaymentHistory.where("company_id = #{@company.id} AND created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first problem is it doesn''t seen to let me compare the create_at attribute with Time.now. Anyone knows the proper way to do this? Thank you, Rodrigo -- 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.
puts Time.now.inspect puts Time.now.inspect.class --output:-- 2011-07-23 23:18:03 -0700 String -- 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-/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.
Need quotes: created_at <= \"#{Time.now}\" AND created_at >= \"#{Time.now-1.month}\" but you can to do that way .where(:company_id => @company.id).where(:created_at => Time.now..Time.now-1.month) 2011/7/24 Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Hi, Id like to do something like that: > > @payment_history = PaymentHistory.where("company_id = #{@company.id} AND > created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first > > problem is it doesn''t seen to let me compare the create_at attribute with > Time.now. > > Anyone knows the proper way to do this? > > Thank you, > Rodrigo > > -- > 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. >-- Fernando Almeida www.fernandoalmeida.net -- 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.
I think you can do this way, too: 1.month.ago On Sun, Jul 24, 2011 at 3:42 AM, Fernando Almeida < fernando-7WGqr3rU1tV1NwFxuVVnt9HuzzzSOjJt@public.gmane.org> wrote:> Need quotes: > > created_at <= \"#{Time.now}\" AND created_at >= \"#{Time.now-1.month}\" > > but you can to do that way > > .where(:company_id => @company.id).where(:created_at => > Time.now..Time.now-1.month) > > > > 2011/7/24 Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> Hi, Id like to do something like that: >> >> @payment_history = PaymentHistory.where("company_id = #{@company.id} AND >> created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first >> >> problem is it doesn''t seen to let me compare the create_at attribute with >> Time.now. >> >> Anyone knows the proper way to do this? >> >> Thank you, >> Rodrigo >> >> -- >> 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. >> > > > > -- > Fernando Almeida > www.fernandoalmeida.net > > -- > 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.
On Sat, Jul 23, 2011 at 9:56 PM, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi, Id like to do something like that: > > @payment_history = PaymentHistory.where("company_id = #{@company.id} AND > created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first >Rodrigo, you might be able to do something like this: time_range = (Time.now - 1.month)..(Time.now) @payment_history = PaymentHistory.where( :company_id => @company.id ).where( :created_at => time_range ).first Good luck, -Conrad> > problem is it doesn''t seen to let me compare the create_at attribute with > Time.now. > > Anyone knows the proper way to do this? > > Thank you, > Rodrigo > > -- > 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.
On Sat, Jul 23, 2011 at 9:56 PM, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @payment_history = PaymentHistory.where("company_id = #{@company.id} AND > created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first > problem is it doesn''t seen to let me compare the create_at attribute with > Time.now."create_at" or created_at ?> Anyone knows the proper way to do this?Showing the actual error message would help provide better answers. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
use array, so try time = Time.now story = PaymentHistory.where(["company_id = ? AND created_at <= ? AND create_at >= ?", company.id, time, time - 1.month ).try(:first) NEVER use direct inserting of values into SQL query and "first" could end with "nil.first", so use try() tom On Jul 24, 2011, at 6:56 , Rodrigo Ruiz wrote:> Hi, Id like to do something like that: > > @payment_history = PaymentHistory.where("company_id = #{@company.id} AND created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first > > problem is it doesn''t seen to let me compare the create_at attribute with Time.now. > > Anyone knows the proper way to do this? > > Thank you, > Rodrigo > > > -- > 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.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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.
sorry, missed one ] story = PaymentHistory.where(["company_id = ? AND created_at <= ? AND create_at >= ?", company.id, time, time - 1.month]).try(:first) On Jul 24, 2011, at 19:55 , Tom Meinlschmidt wrote:> > use array, so try > > time = Time.now > story = PaymentHistory.where(["company_id = ? AND created_at <= ? AND create_at >= ?", company.id, time, time - 1.month ).try(:first) > > NEVER use direct inserting of values into SQL query > > and "first" could end with "nil.first", so use try() > > tom > > On Jul 24, 2011, at 6:56 , Rodrigo Ruiz wrote: > >> Hi, Id like to do something like that: >> >> @payment_history = PaymentHistory.where("company_id = #{@company.id} AND created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first >> >> problem is it doesn''t seen to let me compare the create_at attribute with Time.now. >> >> Anyone knows the proper way to do this? >> >> Thank you, >> Rodrigo >> >> >> -- >> 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. > > -- > ==============================================================================> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > ==============================================================================> > -- > 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.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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.
Can i use .. as in 0..10 with Time ?? On Sun, Jul 24, 2011 at 3:42 AM, Fernando Almeida < fernando-7WGqr3rU1tV1NwFxuVVnt9HuzzzSOjJt@public.gmane.org> wrote:> Need quotes: > > created_at <= \"#{Time.now}\" AND created_at >= \"#{Time.now-1.month}\" > > but you can to do that way > > .where(:company_id => @company.id).where(:created_at => > Time.now..Time.now-1.month) > > > 2011/7/24 Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> Hi, Id like to do something like that: >> >> @payment_history = PaymentHistory.where("company_id = #{@company.id} AND >> created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first >> >> problem is it doesn''t seen to let me compare the create_at attribute with >> Time.now. >> >> Anyone knows the proper way to do this? >> >> Thank you, >> Rodrigo >> >> -- >> 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. >> > > > > -- > Fernando Almeida > www.fernandoalmeida.net > > -- > 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.
Thank you very much guys, it worked -- 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 24 July 2011 20:56, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you very much guys, it workedWhich suggestion worked? Just so that someone who finds this thread can learn from it and not have to ask all over again. Colin -- 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 Sun, Jul 24, 2011 at 6:05 AM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jul 23, 2011 at 9:56 PM, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> Hi, Id like to do something like that: >> >> @payment_history = PaymentHistory.where("company_id = #{@company.id} AND >> created_at <= #{Time.now} AND create_at >= #{Time.now - 1.month}").first >> > > Rodrigo, you might be able to do something like this: > > time_range = (Time.now - 1.month)..(Time.now) > @payment_history = PaymentHistory.where( :company_id => @company.id ).where( > :created_at => time_range ).first > >If the following is the case: class Company has_many :payment_histories def first_paymeny end class PaymentHistory belongs_to :company end Then you should write something like the following: paymant_histories = [] unless @company.nil? time_range = (Time.now - 1.month)..(Time.now) paymant_histories = @company.payment_histories.where( :created_at => time_range ) end @payment_history = paymant_histories.first In the above, we scoped the PaymentHistory from the context of the Company instance and this makes our intentions clear. Next, payment_histories will always return an array. Thus, you''ll have no worries of invoking the first method on it and it will not require using the try method. Good luck, -Conrad Good luck,> > -Conrad > > >> >> problem is it doesn''t seen to let me compare the create_at attribute with >> Time.now. >> >> Anyone knows the proper way to do this? >> >> Thank you, >> Rodrigo >> >> -- >> 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.
> > :created_at => time_range >That part worked =) On Sun, Jul 24, 2011 at 4:58 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24 July 2011 20:56, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thank you very much guys, it worked > > Which suggestion worked? Just so that someone who finds this thread > can learn from it and not have to ask all over again. > > Colin > > -- > 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.