首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >回形针image_tag不显示带有S3和Rails的图像

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

Stack Overflow用户
提问于 2018-01-03 14:42:39
回答 1查看 686关注 0票数 0

我在我的Rails (4.2)应用程序中使用剪纸夹进行S3图像上传。一切都很好,除了image_tag不显示图像而是显示图像的标题这一事实。我遗漏了什么?

recipe.rb

代码语言:javascript
复制
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

配方show.html.erb

代码语言:javascript
复制
<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 %>

更新:解决方案

要使它发挥作用,需要两件事:

  1. s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com"添加到配置中。正如建议的这里那样,这是一个解决方案。
  2. :s3_protocol => :https添加到配置中,因为aws-sdk-2需要这一点(如注释中提到的)。
EN

回答 1

Stack Overflow用户

发布于 2018-01-03 17:45:18

在aws-adk-2中,您需要在配置s3 => :https中显式指定:s3_protocol协议。

最新版本的回形针依赖于aws-sdk-2。所以你必须指定协议。

以这种方式,这将节省您的图像URL与https。

这将帮助您请参阅链接。你也有同样的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48079602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档