Reputation: 1099
I have 2 models Report and Person with report belongs_to person and report has_many reports. I want to make a link in People's Grid 'see reports' to display that specific person's reports
{link_to "Reports", admin_reports_path(:person_id => person.id, :date => Date.today)}
However, when clicking this link it shows all the reports from all the people and not only from today. What am I doing wrong? Thanks!
Reports Controller:
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
end
Upvotes: 0
Views: 206
Reputation: 1071
if you just want to display reports of a person. jus do this in controller
@person = Person.find(params[:person_id)
@reports= @person.reports.where(:date => Date.today)
Upvotes: 1