0
votes

Hey so I'm having some trouble with CarrierWave & MiniMagick this morning uploaded avatar images are not displaying correctly as you can see highlighted in this screenshot I've dug around the html and controllers and can't find what's wrong so I'll post all that here and see if a second set of eyes might be able to find the issue.

Screenshot


Here is AvatarUploader < CarrierWave::Uploader::Base:

All of these params are copied from my lessons at bloc:

  # Process files as they are uploaded:
  # process :scale => [200, 300]
  process :resize_to_fill => [200, 300]
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  version :tiny do
    process resize_to_fill: [20, 20]
  end

  version :small do
    process resize_to_fill: [30, 30]
  end

  version :profile do
    process resize_to_fill: [45, 45]
  end

Here is a snippet from application.html.erb

Note: I am also using devise

<% if current_user %>
  <%= image_tag(current_user.avatar.tiny.url) if current_user.avatar? %> Hello <%= link_to (current_user.name || current_user.email), edit_user_registration_path %>! 
  <%= link_to "Sign Out", destroy_user_session_path, method: :delete %>
<% else %>
  <%= link_to "Sign In", new_user_session_path %> or <%= link_to "Sign Up", new_user_registration_path %>
<% end %>

And lastly here is my Users controller:

class UsersController < ApplicationController
  before_action :authenticate_user!

  def update
    if current_user.update_attributes(user_params)
      flash[:notice] = "User information updated"
      redirect_to edit_user_registration_path
    else
      flash[:error] = "Invalid user information"
      redirect_to edit_user_registration_path
    end
  end

  private

  def user_params
    params.require(:user).permit(:name, :avatar)
  end
end

If you need to see more files, ask and I'll add them.

1
Can you please try image_tag current_user.avatar.url(:tiny) ?Kiloreux
What is the tag generating? Please add the existing output to your question.errata
@Kiloreux That worked after a rake db:reset and a server restart. Thanks!Jeff Wilkey
I posted it as an answer , to be more clear as answered question .Kiloreux

1 Answers

1
votes

The answer to this , is that you should use

image_tag current_user.avatar.url(:tiny)