Ruby on Rails Sunday, March 6, 2016

On 6 March 2016 at 09:52, Naveed Alam <lists@ruby-forum.com> wrote:
> Colin Law wrote in post #1181949:
>> On 6 March 2016 at 09:14, Naveed Alam <lists@ruby-forum.com> wrote:
>>>>> model, method name is full_name which says full_name undefined.
>>> Extracted source (around line #5):
>>> Application Trace | Framework Trace | Full Trace
>>> {"id"=>"2"}
>> Error messages are often a little tricky to understand but there is
>> often useful information there if the message is considered carefully.
>> Note that it is saying undefined method `full_name' for nil:NilClass.
>> This means that you have tried to call the method full_name on an
>> object that is nil. Looking at the code this means that @employee is
>> nil. You need to work out why that is so.
>>
>> An easy way of doing simple debugging is to insert into your code lines
>> such as
>> logger.info( "Employee: #{@employee.inspect} )
>> That will insert a line into development.log showing the value of
>> @employee.
>>
>> Colin
>
> Dont know if I am right, but I tried this and the log is below:
> <%= logger.info( "Employee: #{@employee.inspect}") %>
> ...

It is not necessary to post the complete log, only the bits around the failure.

> ActionView::TemplateError (undefined method `full_name' for
> nil:NilClass) on line #5 of app/views/employee/add_rosterduty.html.erb:
> 2: <%= show_header_icon %>
> 3: <h1><%= "Roster Duty" %></h1>
> 4: <div class='header-sep'>|</div>
> 5: <div class='sub-header'><%= @employee.full_name %>
> 6: <%= logger.info( "Employee: #{@employee.inspect}") %>

There is not much point putting the log line after the line that is
causing processing to stop due to the error. Also there is not much
point putting it anywhere in that bit of code as we already know (from
the error message) that it is nil. I expected that you would put it
in the area where you are setting up @employee to try to work out why
it is nil.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvNGceq571qx5aZWPeO--eGJvbES6bSA06q2nBJc__kuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment