Ruby on Rails Thursday, June 25, 2015



On Fri, Jun 26, 2015 at 7:20 AM, David Williams <lists@ruby-forum.com> wrote:
In my application.html.erb, I have a navigation bar that stores the user
avatar. He or she should be able to return to the main index or traverse
through the different controllers without issue. I seem to be getting a
"Cannot find avatar for type ActiveRecord::Relation"

undefined method `avatar' for nil:NilClass

Application.html.erb
<%= if user_signed_in? %>
<li class="round-image-50"><%= image_tag(@user.avatar.url(:thumb),
unless: avatar.nil?) %></li>

I think error message is obvious
you got that error because @user was nil
if you're using devise, you can try this instead "current_user.avatar.url(:thumb)"


--
Mou Dareka no, tame janakutte
Jibun no Tame ni Warette Iru

( Aqua Timez - Alones )

--
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/CANryp8%3D690wESPTJT0S%3DSmwpXr8yH6EVtXk_49DRMvhvVyjZOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment