没有ID,找不到时间表

时间:2013-08-25 20:22:49

标签: ruby-on-rails ruby ruby-on-rails-3

我使用activerecord

将一些Timesheet对象组合在一起
scope :grouped_by_user_with_total_time, lambda {
  group(:user_id, :day).select('user_id, SUM(time_worked) AS time_total, day, editable, approvable, accepted, comments')
}

在我这样做之后,现在当我尝试在分组对象上调用approve方法时,我得到了错误

Couldn't find TimeSheet without an ID

它突出了我的方法中的第三行

def approve
if params[:time_sheets]
@time_sheets = []
*t = TimeSheet.find(params[:time_sheets])**  
if t.instance_of?(Array)
  @time_sheets = t
else
  @time_sheets << t
end
successful = []
unsuccessful = []

@time_sheets.each do |timesheet|
  unless timesheet.approved
    timesheet.approve
    if timesheet.save
      successful << timesheet
    else
      unsuccessful << timesheet
    end
  end
end
end

我对activerecord不是很有经验,我很好奇分组如何影响这些方法,以及我需要做些什么来使方法可以从他们刚刚接受单个对象之前到方法将在哪里工作所有分组的对象。

0 个答案:

没有答案
相关问题