On 7 February 2016 at 20:11, David Williams <[email protected]> wrote: > Hello to my fellow rails devs. > > I'm currently receiving an "undefined method `location' for > nil:NilClass" exception error in one of my views when the user hasn't > filled in the form for their profile.
Read the error carefully, it says you have called location on something that is nil. > > How would I approach bypassing this error in the cleanest way? > > I've tried to use the method below, but the error still persist. > > <h2><i class="fa fa-street-view"></i> <% if @user.profile.location.nil? > ? "" : @user.profile.location %> <% end %></h2> You are testing @user.profile.location for nil, but it is @user.profile that 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtSzQf_vp9YzbgWbwEdQFVq6pHJRLQD_w42GFE-SSx76w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

