简体   繁体   English

回形针image_tag不显示带有S3和Rails的图像

[英]Paperclip image_tag does not show image with S3 and Rails

I am using Paperclip for S3 image uploading in my Rails (4.2) app. 我在Rails(4.2)应用程序中使用Paperclip进行S3图像上传。 Everything works fine, except of the fact that the image_tag does not show the image but the title of the image. 一切正常,除了image_tag不显示图像而是图像标题。 What am I missing? 我想念什么?

recipe.rb recipe.rb

class Recipe < ActiveRecord::Base

  has_attached_file :image, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }


  validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
  validates_with AttachmentSizeValidator, attributes: :image, less_than: 1.megabytes

end

Recipe show.html.erb 食谱show.html.erb

<p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= @recipe.name %>
</p>

<div class="col-xs-12" style="height:400px">
  <%= image_tag @recipe.image.url(:original) %>
</div>


<%= link_to 'Edit', edit_recipe_path(@recipe) %> |
<%= link_to 'Back', recipes_path %>

UPDATE: Solution 更新:解决方案

Two things are needed to make it work: 要使其工作,需要做两件事:

  1. Add s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com" to config. s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com"到配置中。 This is a workaround as suggested here . 这是此处建议的解决方法。
  2. Add :s3_protocol => :https to config as aws-sdk-2 needs this explicitly (as mentioned in the comments). :s3_protocol => :https添加到配置中,因为aws-sdk-2明确需要此功能(如注释中所述)。

In aws-adk-2 you need to specify s3 protocol explicitly in your configuration :s3_protocol => :https. 在aws-adk-2中,您需要在配置中显式指定s3协议:s3_protocol =>:https。

latest versions of paperclip depend on aws-sdk-2. 回形针的最新版本取决于aws-sdk-2。 so you have to specify the protocol. 因此您必须指定协议。

In this way this way this will save your image URL with https. 这样,这将使用https保存您的图像URL。

This answe will help you see the link . 这将帮助您查看链接 you have the same problem. 你有同样的问题。

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

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