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/.