4

我想要像这样的方法

Shift.by_quarter(1) => each shift in first quarter of current year

现在我正在按日期选择季度班次

Shift
  scope :by_quarter, lambda{|date| 
    where starts_at: date.beginning_of_quarter..date.end_of_quarter}
4

1 回答 1

5

我的解决方案:

scope :by_quarter, lambda{|quarter| 
    date = Date.new(Date.today.year, quarter * 3)
    where starts_at: date.beginning_of_quarter..date.end_of_quarter }
于 2013-10-18T11:10:32.303 回答