0

前几天还在用,不知道怎么回事。。。

**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

可能是日期为零吗?如何解决这个问题><

非常感谢比利

4

1 回答 1

0

正如 abha 已经说过的,leave.applicant至少有一片叶子是 nil。

转到您的数据库并找出它是哪个。然后弄清楚如何处理你的叶子。也删除它们,重新添加丢失的申请人或任何数据迁移可能是明智的。

如果申请人失踪,一个快速的解决办法是跳过:

html += content_tag(:div, leave.applicant.name, class: 'leaveName') if leave.applicant.present?

如果您在应用程序中正确配置了删除级联,我也会看看。这通常会导致此类问题。如果您想在这方面强制执行安全性,您应该添加数据库约束,以确保不会删除任何引用的实体。

于 2012-06-26T12:48:17.467 回答