2012-10-04 24 views
0

我有2個模型報告和報告belongs_to人與報告has_many報告。 我想在人民電網 '看報告' 的鏈接,以顯示該特定人的報告如何顯示特定人員的報告?

{的link_to 「報告」,admin_reports_path(:爲person_id => person.id,:日期=> Date.today)}

但是,點擊此鏈接時,它會顯示來自所有人的所有報告,而不僅僅是從今天開始。 我在做什麼錯? 謝謝!

報告控制器:

高清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 

+0

u能張貼CONTROLER代碼 – Amar

+0

我編輯我的問題 –

回答

1

,如果你只是想顯示一個人的報告。強制執行此操作控制器

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

我使用主動聯繫,如果我給path參數(@reports),它只是表明管理員/ reports.I得到的人。身份證和日期參數在URL中,所以它有點腥 –

+0

不明白你的要求是什麼。你可以請elababorate –