CarrierWave / MiniMagick头像无法显示

时间:2015-05-16 20:08:34

标签: ruby-on-rails ruby imagemagick carrierwave minimagick

嘿所以我在CarrierWave& amp; MiniMagick今天早上上传的头像图像显示不正确,因为你可以看到在这个截图中突出显示我已经挖了html和控制器,但是找不到有什么问题所以我会在这里发布所有内容,看看是否有第二组眼睛也许能够找到问题。

Screenshot

这是AvatarUploader< CarrierWave ::上传::基地:

所有这些参数都是从我的课程中复制的:

  # 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

以下是application.html.erb

的摘录
  

注意:我也在使用设计

<% 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 %>

最后这是我的用户控制器:

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

如果您需要查看更多文件,请询问,我会添加它们。

1 个答案:

答案 0 :(得分:1)

答案是,你应该使用

image_tag current_user.avatar.url(:tiny)