【发布时间】:2019-10-12 14:15:17
【问题描述】:
在 Heroku 上部署用 Ruby On Rails 编写的 Web 应用程序(在线商店)后,不会显示数据库中的产品。我部署并使用“git push heroku master”迁移数据库,然后使用“heroku run rails db:migrate”。我正在使用 PostgreSQL 和 Paperclip gem 上传图片。
我尝试从已部署的应用程序上传新产品,它可以正常工作。
<% @products.each do |product| %>
<div class="col-lg-4 col-md-6 mb-4">
<div class="cart h-100">
<% if product.image.present? %>
<%= link_to image_tag(product.image.url(:thumb)), product_path(product)%>
<% end %>
<div class="card-body">
<h4 class="card-title"><%= product.name %></h4>
<h5><%= product.price %></h5>
<p class="card-text"><%= product.description %></p>
</div>
<div class="card-footer">
<% if current_user && current_user.admin? %>
<%= link_to 'Edit', edit_product_path(product) %>
<%= link_to 'Delete', product_path(product), method: :delete, data: { confirm: 'Are you sure?' } %>
<% elsif current_user && !current_user.admin %>
<%= form_tag(line_items_path(product_id: product.id)) do %>
<%= number_field_tag(:quantity, 1) %>
<%= submit_tag('Add to shopping cart') %>
<% end %>
<% elsif !user_signed_in? %>
<% end %>
</div>
</div>
</div>
<% end %>
我希望显示来自数据库的项目,但迁移后,产品仍然丢失,我只能从部署的应用程序中添加它们。
【问题讨论】:
-
"我希望显示数据库中的项目,但迁移后,产品仍然丢失,我只能从部署的应用程序中添加它们。"什么迁移?您希望这些产品从哪里出现?
-
您不希望本地/开发环境中的
products出现在您的 Heroku/生产环境中,是吗? -
问题编号。 1 是我无法从本地环境迁移/显示我的产品。问题编号。 2是一旦从部署的应用程序添加
product,文本数据只出现图像不显示。这是否意味着我需要另一个位置来存储我的文件?如果是,你会推荐什么?感谢您的帮助! -
我阅读了这篇关于图像上传的文章devcenter.heroku.com/articles/…,但我在配置方面遇到了一些问题,同时我找到了另一个解决方案:Rails 5 的 Active Storage - 我会尝试实现它跨度>
标签: ruby-on-rails database heroku deployment ruby-on-rails-5