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.
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>
OR
<% if @user.profile.location.present? %>
<h2><i class="fa fa-street-view"></i>Location <%=
@user.profile.location %></h2>
<% end %>
--
Posted via http://www.ruby-forum.com/.
--
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/bec4fc2d4903a2e7300cedf5775b0567%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment