简体   繁体   English

将default_url回形针图像放在Rails 4.1应用程序的公共目录中有什么问题吗?

[英]Is there anything wrong in putting default_url paperclip images in the public directory of a Rails 4.1 app?

I have was seeing several discussions (on stackoverflow here and here , and as a bug on paperclip here ) around the best way to tell the default_url of images using Paperclip and Rails so that they work fine in production with the asset pipeline. 我已经被(计算器上看到一些讨论在这里这里 ,并作为回形针错误这里 )各地最好的方式告诉使用回形针和Rails图像的DEFAULT_URL,使他们在生产中正常工作与资产管道。 All solutions appear quite complicate. 所有解决方案都显得很复杂。

Is there anything wrong in putting the default images in the public/ directory of the Rails app? 将默认图像放在Rails应用程序的public /目录中有什么问题吗? Anything I need to worry down the line or that I am missing? 我有什么需要担心的事情或者我想念什么吗?

If I put images in the public/ directory and access them with the code below all appears to work correctly. 如果我将图像放在public /目录中,并使用以下代码访问它们,则所有代码似乎都可以正常工作。

has_attached_file :image, 
  styles: {original: "1000x1000", medium: "530x530#", thumb: "300x300#"}, 
  default_url: "/default-avatar_:style.png"

I generally, by convention alone include the missing styles images in the assets directory. 通常,仅按照惯例,我通常在资产目录中包含缺少的样式图像。 You don't need any extra coding or complex mechanisms to have paperclip utilize them. 您不需要任何额外的编码或复杂的机制即可使回形针利用它们。

#Images within assets:
/app/assets/images/default-avatar_original.png
                   default-avatar_medium.png
                   default-avatar_thumb.png


# paperclip config in /app/models/user.rb
has_attached_file :image, :styles => {:original => ["1000x1000", :png],
                                       :medium   => ["530x530#", :png], 
                                       :thumb    => ["300x300#", :png] }, 
                :default_url => "/assets/default-avatar_:style.png"

Note that when specifying default_url, you exclude the /image/ directory. 请注意,当指定default_url时,将排除/ image /目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM