如何为特定人员显示报告?

时间:2012-10-04 09:13:30

标签: ruby-on-rails activeadmin

我有2个模型Report和Person with report belongs_to person并报告has_many报告。 我想在人们的网格中建立一个链接,并查看报告'显示特定人员的报告

{link_to" Reports",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

1 个答案:

答案 0 :(得分:1)

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

 @person = Person.find(params[:person_id)
 @reports= @person.reports.where(:date => Date.today)