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>
User.rb
has_attached_file :avatar, :styles => { :medium => "200x200>", :thumb =>
"100x100>" }, :unless => "avatar.blank?",
:url =>
"/assets/users/:id/:style/:basename.:extension",
:path =>
":rails_root/public/assets/users/:id/:style/:basename.:extension"
validates_attachment_content_type :avatar, :content_type =>
/\Aimage\/.*\Z/
The avatar uploads successfully when the user registers, and the file
itself is attached to the user object.
Do you have a solution for this problem? And how would you enable the
app to show all user avatars globally?
--
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/8cde1d090eae457a54e0fe466aae181a%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment