- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我正在尝试使不同版本的默认图像适用于我的 avatar_uploader。我之前使用过 2 个版本,但不是我添加了 4 个版本,似乎有一个我无法弄清楚的错误。当我引用我的 :small 版本的默认图像时,它显示 :large 版本的默认值。我已经从我的 public/images/fallback 文件夹中删除了 large_avatar_defualt.png 文件,并确认该请求确实在寻找 large_avatar_default.png。正如您在下面的代码中看到的那样,我指向了正确的头像版本,知道为什么会发生这种情况吗?
Started GET "/users/example123/following" for 127.0.0.1 at 2011-10-29 13:16:31 -0700
Processing by UsersController#following as JS
Parameters: {"id"=>"example123"}
User Load (62.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
User Load (3.5ms) SELECT "users".* FROM "users" WHERE "users"."cached_slug" = 'example123' LIMIT 1
User Load (2.1ms) SELECT "users".* FROM "users" INNER JOIN "relationships" ON "users".id = "relationships".followed_id WHERE (("relationships".follower_id = 1)) LIMIT 30 OFFSET 0
Rendered users/_user.html.erb (3.5ms)
Rendered users/_users.html.erb (5.5ms)
Rendered users/following.js.erb (7.5ms)
Completed 200 OK in 312ms (Views: 25.2ms | ActiveRecord: 69.2ms)
Started GET "/images/fallback/large_avatar_default.png" for 127.0.0.1 at 2011-10-29 13:16:31 -0700
ActionController::RoutingError (No route matches "/images/fallback/large_avatar_default.png"):
Rendered /Users/iHal/.rvm/gems/ruby-1.9.2-p290@rails3/gems/actionpack-3.0.7/lib/action_dispatch/mid
dleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)
<% if users.empty? %>
<%= @empty_msg %>
<% else %>
<%= @title %>
<% users.each do |user| %>
<%= render 'user', :user => user %>
<% end%>
<% end%>
<div>
<%= small_avatar_for user %>
<%= link_to user.name, user %>
<%= link_to user.username, user %>
</div>
module UsersHelper
def tiny_avatar_for(user)
image_tag(user.avatar_url(:tiny).to_s, :alt => "avatar", :class => "round-3")
end
def small_avatar_for(user)
image_tag(user.avatar_url(:small).to_s, :alt => "avatar", :class => "round-3")
end
def medium_avatar_for(user)
image_tag(user.avatar_url(:medium).to_s, :alt => "avatar", :id => "align-middle", :class => "round-3")
end
def large_avatar_for(user)
image_tag(user.avatar_url(:large).to_s, :alt => "avatar", :class => "round-10", :id => "center-big-avatar")
end
end
# Include RMagick or ImageScience support:
include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
#storage :file
# storage :s3
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
def default_url
"/images/fallback/" + [tiny, "tiny_avatar_default.png"].compact.join('_')
"/images/fallback/" + [small, "small_avatar_default.png"].compact.join('_')
"/images/fallback/" + [medium, "medium_avatar_default.png"].compact.join('_')
"/images/fallback/" + [large, "large_avatar_default.png"].compact.join('_')
end
# Process files as they are uploaded:
# process :scale => [200, 300]
process :resize_to_fit => [600, 600]
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
version :large do
process :resize_to_fill => [165, 165]
end
version :medium do
process :resize_to_fill => [75, 75]
end
version :small do
process :resize_to_fill => [45, 45]
end
version :tiny do
process :resize_to_fill => [20, 20]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
def filename
"avatar.#{File.extname(original_filename).downcase}" if original_filename
end
def filename
if Rails.env.production?
name_s3
else
name_file
end
end
def name_s3
# S3 storage class is Carrierwave::Storage::S3::File
"avatar.#{File.extname(original_filename).downcase}" if original_filename
end
def name_file
# :file storage class is Carrierwave::Storage::File
"avatar.#{model.avatar.file.extension}" if original_filename
end
end
最佳答案
这应该可以解决问题!
def default_url
"/images/fallback/" + [version_name, "avatar_default.png"].compact.join('_')
end
关于ruby-on-rails - rails 3 : carrierwave default_url bug, 没有使用正确的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7941515/
我正在尝试配置 Paperclip 以根据实例的类别属性提供不同的缺失图像。对象的每个类别都有自己的缺失图像。 这是我的第一次: 编辑以添加完整模型: class Service true ha
我认为我没有正确理解这一点,但是我如何为用户提供默认图像? def default_url "/images/fallback/" + [version_name, "default
我将 s3 与 Paperclip 一起使用,效果很好。但是,我遇到了 default_url 缺少附件的问题。我希望 default_url 成为与其他文件相同的 s3 存储桶中的 :attache
我在 Rails 3 应用程序中使用 carrierwave 从远程源上传文件并将其存储在我服务器的文件系统中。我有一个完全标准的设置, uploader 安装在与图像关联的模型上。 它在 99.9%
嗨,我正在尝试使不同版本的默认图像适用于我的 avatar_uploader。我之前使用过 2 个版本,但不是我添加了 4 个版本,似乎有一个我无法弄清楚的错误。当我引用我的 :small 版本的默认
我的用户模型有头像附件 class User has_attached_file :avatar, styles: { medium: '300x300#', thumb: '150x150#'
class ImageUploader [50, 50] end version :main do process :auto_orient process :resize_
我是一名优秀的程序员,十分优秀!