我花了一整天时间尝试解决这个问题。我解决了一半,但我无法解决剩下的问题。我正在练习使用Rails框架上传图像并将网站部署到Heroku并将图像存储到S3 Amazonaws。
我可以将图像存储到S3,但Heroku不会在网站上显示图像。
我注意到S3 Amazonaws和Heroku图像显示的链接不一样。
S3将图片存储在此链接下:
https://s3-us-west-1.amazonaws.com/pictures333/pins/images/000/000/024/original/S.Newman__A_Place_of_Inspiration__2017__Oil_on_Canvas__36x48___3500.jpg https://momo333.herokuapp.com/pins/29
Heroku网站在此链接下显示图片:
在检查员中,我通过添加aws-region部分' -us-west-1'进行了测试。在' s3'之间和' amazonaws'它显示图像。
但是,我不确定如何从S3 Amazon或我的Rails代码永久修改链接。
在Gemfile中:
gem 'rails', '~> 5.1.4'
gem 'puma', '~> 3.7'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails', '~> 4.3', '>= 4.3.1'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'haml', '~> 5.0', '>= 5.0.4'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'
gem 'simple_form', '~> 3.5'
gem 'devise', '~> 4.3'
# gem 'paperclip', '~> 5.1'
gem 'masonry-rails', '~> 0.2.4'
gem 'acts_as_votable', '~> 0.11.1'
gem 'will_paginate-bootstrap', '~> 1.0', '>= 1.0.1'
# gem 'aws-sdk', '~> 3.0', '>= 3.0.1'
# gem 'aws-sdk', '2.10.47'
# gem 'aws-sdk', '~> 3.0.0.rc7'
# gem 'aws-sdk', '~> 2.10', '>= 2.10.86'
# gem "rails", ">= 4.2"
gem "paperclip", ">= 5.0"
gem "aws-sdk", ">= 2.0"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'sqlite3'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
应用/视图/针/ show.html.haml
#pin_show.row
.col-md-8.col-md-offset-2
.panel.panel-default
.panel-heading.pin_image
= image_tag @pin.image.url(:medium)
.panel-body
%h1= @pin.title
%p.description= @pin.description
%p
Submiited by:
= @pin.user.email
.panel-footer
.row
.col-md-6
%p.user
Submitted by
= @pin.user.email
.col-md-6
.btn-group.pull-right
= link_to like_pin_path(@pin), method: :put, class:'btn btn-default' do
%span.glyphicon.glyphicon-heart
= @pin.get_upvotes.size
- if user_signed_in?
= link_to "Back", root_path, class:'btn btn-default'
= link_to "Edit", edit_pin_path, class:'btn btn-default'
= link_to "Delete", pin_path, method: :delete, data: {confirm: "Are you sure?"}, class:'btn btn-default'
我很感激你的回答,谢谢!