回形针不显示图像,即使URL/图像位于正确的位置 [英] Paperclip not showing image even though URL/images in correct places

查看:61
本文介绍了回形针不显示图像,即使URL/图像位于正确的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用回形针将化身附加到我的rails应用程序的用户个人资料中.我按照回形针github上的说明进行初始化并附加到我的应用程序.

Using Paperclip to attach avatars to User profiles for my rails application. I followed the instructions on the paperclip github to initialize and attach to my app.

我在public/images/medium/missing.png中有一张图片,在这两种情况下(当我上载或默认后退时)都没有图片.我已经检查了我的目录,并且有一张图片,上面写着它正在寻找,但是没有抓住它.另外,当我尝试上传图像时,我知道图像已正确上传,因为在rails控制台中调用User时,会显示所有正确附加的信息.

I have an image in the public/images/medium/missing.png and for both cases (when I upload or when I fallback on the default) I get no image. I've checked my directory and there is an image where it says it is looking but does not grab it. Additionally when I have tried uploading images, I know the image is uploaded correctly because when calling the User in rails console shows all the information properly attached.

我将视图中的图片称为:

I am calling the image in my view like:

<%= image_tag(@blog.user.avatar.url(":medium"), :class => "image-circle avatar") %>

我在User模型中的Paperclip声明如下:

my Paperclip declaration in the User model looks like the following:

has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#"}, :default_url => "/public/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

真的不确定发生了什么.当我检查加载不正确的图像时出现的路由错误直接指向本地服务器中的图像.它无法捕获丢失的文件或上载的文件这一事实也让我感到茫然.任何帮助将不胜感激!

Really not sure what is going on. The route errors that appear when I inspect the improperly loaded image point directly to the image in my local server. And the fact that it can't grab either the missing or the uploaded file also has me at a loss. Any help would be super appreciated!!

当我检查具有上传头像的用户时,请很好地衡量输出:

And for good measure the output when I examine a user with an uploaded avatar:

avatar_file_name: "11390219_10206114805925816_6595348111261743639_n.j...", avatar_content_type: "image/jpeg", avatar_file_size: 101926, avatar_updated_at: "2015-07-10 18:51:44"> 

提前谢谢!

编辑

这是提供404错误的URL:

This is the URL that is providing the 404 error:

http://localhost:3000/images/medium/missing.png 

在我的本地目录中时,它会变成"root/public/images/medium/missing.png"

while in my local directory it goes "root/public/images/medium/missing.png"

不知道它是如何无法抓住它的,除非我只是在某个地方缺少真正明显的东西.(我也尝试过将公众路由到那里,但无济于事).

not sure how its not grabbing it, unless I am just missing something really obvious somewhere. (i tried hard routing the public in there as well, but to no avail).

推荐答案

编辑

您可能根本就没有提供静态资产,请添加:

There is the possibility that you're simply not serving the static assets, add:

config.serve_static_assets = true

转到您的development.rb

to your development.rb

原始帖子

在application.rb(或特定于环境的文件)中,您应该具有config.paperclip_defaults = {...},这是文档中的链接:

In you application.rb ( or an environment specific file ), you should have a config.paperclip_defaults = { ... }, here is the link in the docs: https://github.com/thoughtbot/paperclip#defaults

以下是使用雾的示例:

config.paperclip_defaults = {
  :storage => :fog,
  :fog_credentials => {
    :provider => "Local",
    :local_root => "#{Rails.root}/public"
  },
  :fog_directory => "",
  :fog_host => "localhost:3000"
}

您的应用程序中是否有类似的东西?我刚刚在我的一个应用程序上进行了测试,并且能够上载图像,但是如果没有paperclip_defaults哈希,就看不到任何图像.另外,更新配置文件后,请不要忘记重新启动应用程序.我希望这会有所帮助!

Do you have something like that in your application? I just tested on an app of mine, and I was able to upload an image, but not to see any without the paperclip_defaults hash. Also, don't forget to restart your app after you update the config files. I hope this helps!

这篇关于回形针不显示图像,即使URL/图像位于正确的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆