Rails 6图像显示在heroku本地而不是服务器上

时间:2020-09-06 17:41:06

标签: ruby-on-rails ruby heroku

我在Rails应用程序上制作了一个红宝石。它可以在本地的heroku上完美运行,但是在部署到heroku后,这些图像会损坏。

图像将以.png格式保存在图像文件夹,资源文件夹和app文件夹中。 在我的控制台上也出现404错误:

jorden.png:1 GET https://shoehouse-org.herokuapp.com/assets/jorden.png 404 (Not Found)

directories

#views/shoes/index.html.erb
  <% @shoes.each do |shoe| %>
  <div class="column">
    <img src=<%= "/assets/#{shoe.img_url}" %> alt="Snow" style="width:100%">    
  </div>

我还在production.rb文件中将以下几行设置为true。

      config.serve_static_assets = true
      config.assets.compile = true
      config.assets.digest = true

宝石文件包括:

gem 'pg', '>= 0.18', '< 2.0'
gem 'sass-rails', '~> 5'

1 个答案:

答案 0 :(得分:0)

尝试

<img src=<%= "#{image_url(shoe.img_url)}" %> alt="Snow" style="width:100%">