几天前工作,不知道出了什么问题......
**undefined method `name' for nil:NilClass**
Extracted source (around line #26):
23: %td= number_with_precision(employee.compensation_leave_balance, precision:1)
24: #calendar.tab-pane.fade
25: = calendar(:year => 2012, :month => 6, :first_day_of_week => 1, summary: "Leave Calendar", calendar_title: "June", month_header: true) do |date|
26: - render_leave_calendar_cell(date)
27: #trash.tab-pane.fade
28: = render 'table', leaves: @leaves.where(deleted: true)
app/helpers/leaves_helper.rb:11:in `block in events_for'
app/helpers/leaves_helper.rb:10:in `events_for'
app/helpers/leaves_helper.rb:4:in `render_leave_calendar_cell'
app/views/human_resources/leaves/index.html.haml:26:in `block in _app_views_human_resources_leaves_index_html_haml__145883348_88978910'
app/helpers/calendar_helper.rb:146:in `call'
app/helpers/calendar_helper.rb:146:in `block in calendar'
app/helpers/calendar_helper.rb:145:in `upto'
app/helpers/calendar_helper.rb:145:in `calendar'
app/views/human_resources/leaves/index.html.haml:25:in `_app_views_human_resources_leaves_index_html_haml__145883348_88978910'
真的不知道出了什么问题
a/h/leaves_helper.rb
1 module LeavesHelper
2 def render_leave_calendar_cell(date)
3 html = content_tag(:span, date.day, class: 'dayDisplay')
4 html += content_tag(:div, events_for(date))
5 raw(html)
6 end
7
8 def events_for(date)
9 html = ""
10 current_company.leaves.where("start_date <= '#{date}' and return_date > '#{date}'").where(deleted: false).each do |leave|
11 html += content_tag(:div, leave.applicant.name, class: 'leaveName')
12 end
13 raw html
14 end
可能是约会的日期吗?如何解决这个&gt;&lt;
非常感谢 比利答案 0 :(得分:0)
leave.applicant
是零。
转到您的数据库,找出它是什么。然后弄清楚如何处理你的叶子。删除它们,重新添加丢失的申请人或数据迁移可能是明智的。
如果申请人失踪,将快速解决问题:
html += content_tag(:div, leave.applicant.name, class: 'leaveName') if leave.applicant.present?
如果您在应用程序中正确配置了删除级联,我也会看看。这通常会导致这样的问题。如果要在这方面强制执行安全性,则应添加数据库约束,以确保不会删除任何引用的实体。