0

我有 2 个模型 Report 和 Person 以及 report belongs_to person 和 report has_many 报告。我想在人民网格“查看报告”中创建一个链接以显示该特定人员的报告

{link_to "报告", admin_reports_path(:person_id => person.id, :date => Date.today)}

但是,当单击此链接时,它会显示所有人的所有报告,而不仅仅是今天的报告。我究竟做错了什么?谢谢!

报告控制器:

def create_daily

person_id = @person.id
reports = params[:reports] || []
date = Date.today

  reports.each do |index, attributes|
  project = Project.find_by_short_name(attributes[:short_name])
  project_id = project.id if project
  date = Date.parse(attributes[:date])

  report = Report.where(:person_id => person_id, :project_id => project_id, :date => date).first_or_initialize
  report.person_id     = person_id
  report.project_id    = project_id
  report.date          = date unless report.date  # Do not overwrite if already existing
  report.day_off       = attributes[:day_off] == 'true'
  report.body          = attributes[:body].to_s.strip
  report.time_estimate = attributes[:time_estimate].to_s.strip
  report.save
end

respond_to do |format|
  format.html { redirect_to reports_url }
  format.json { render :json => { :reports => Report.by_reporter(current_user).for_date(date) } }
end

结尾

4

1 回答 1

1

如果您只想显示一个人的报告。只需在控制器中执行此操作

 @person = Person.find(params[:person_id)
 @reports= @person.reports.where(:date => Date.today) 
于 2012-10-04T10:14:03.770 回答