Putting Date and 1.month.ago together? Putting Date and 1.month.ago together? ruby ruby

Putting Date and 1.month.ago together?


Just 1.month.ago is enough, you don't need to prepend Date.today to 1.month.ago because 1.month.ago starts from today


You have mistake in your Date syntax, you might want to use something like this:

def self.last_month # Show only products of last month.  where(:purchase_date => 1.month.ago.beginning_of_month..1.month.ago.end_of_month)enddef self.this_month # Show only products of this month.   where(:purchase_date => Date.today.beginning_of_month..Date.today.end_of_month)end


Maybe:

def self.this_month    where(:purchase_date =>(Date.today - 1.month)..Date.todayend