I had set up a default avatar when I set up Carrierwave. It is no longer working. I tried this work around in the view, but it isn't working either. The default is always show, even after the avatar image gets uploaded by the user.
In my view: <% if @avatar.nil? %> <%= link_to image_tag(('/assets/images/default.png').to_s), user %> <% else %> <%= link_to image_tag(user.avatar.to_s, collection: user), user %> <% end %>
user.rb: validates_presence_of :avatar, allow_blank: true
I had also tried this as a workaround but didn't work:
def create
@user = User.new(user_params)
#@avatar = "/assets/images/'default.png'"
if @user.save
sign_in @user
flash[:success] = "Welcome!"
redirect_to :back
else
flash[:error] = "Please fill in required information."
render 'new'
end
end
session_helper.rb
def avatar_changed?
@avatar = Avatar.find(params[:id])
if user && user.read_attribute(:avatar).present?
user.read_attribute(:avatar)
else
user.avatar.recreate_versions!
avatar.save!
end
end
Any suggestions on how I can set it up to have a default image but have it change if/when the user uploads one personally?
Thanks