Lea*_*RoR 5 ruby ruby-on-rails ruby-on-rails-3
我怎么会把Date并1.month.ago在一起的时候我已经叫日期属性:purchase_date,并希望把它的一类方法中?
def self.last_month # Show only products of last month.
where(:purchase_date => Date.today.1.month.ago.end_of_month..Date.1.month.ago.beginning_of_month)
end
Run Code Online (Sandbox Code Playgroud)
控制台给出语法错误并将其删除Date.today,与我的其他方法相比,给出了空白结果:
def self.this_month # Show only products of this month.
where(:purchase_date => Date.today.beginning_of_month..Date.today.end_of_month)
end
Run Code Online (Sandbox Code Playgroud)
你的日期语法有错误,你可能想要使用这样的东西:
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)
end
def self.this_month # Show only products of this month.
where(:purchase_date => Date.today.beginning_of_month..Date.today.end_of_month)
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11284 次 |
| 最近记录: |