【问题标题】:Comments not working once deployed to Heroku部署到 Heroku 后评论不起作用
【发布时间】:2020-09-22 03:49:18
【问题描述】:

我最近向 Heroku 部署了一个应用程序,但我的 cmets 出现了问题。它在开发中运行良好,但在生产中我收到以下错误。看起来 Heroku 对我的 cmets.index.html.erb 文件有问题(也包括在下面)有人能指出我正确的方向吗?它说 cmets.recipe_id 不存在,但我不明白为什么它在开发中会很好但一旦部署就不行?谢谢!

2020-09-22T03:42:18.459074+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf] ActionView::Template::Error (PG::UndefinedColumn: ERROR:  column comments.recipe_id does not exist
2020-09-22T03:42:18.459075+00:00 app[web.1]: LINE 1: SELECT "comments".* FROM "comments" WHERE "comments"."recipe...
2020-09-22T03:42:18.459076+00:00 app[web.1]: ^
2020-09-22T03:42:18.459076+00:00 app[web.1]: HINT:  Perhaps you meant to reference the column "comments.recipe".
2020-09-22T03:42:18.459077+00:00 app[web.1]: ):
2020-09-22T03:42:18.459077+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]      5: <% end %>
2020-09-22T03:42:18.459078+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]      6:
2020-09-22T03:42:18.459078+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]      7: <ul>
2020-09-22T03:42:18.459079+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]      8: <% @comments.each do |c|%>
2020-09-22T03:42:18.459081+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]      9:   <li><%= c.user.username%> says "<%= c.content%>" about this recipe: <strong><%= link_to c.recipe.title, recipe_path(c.recipe_id) %></strong></li>
2020-09-22T03:42:18.459082+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]     10:
2020-09-22T03:42:18.459082+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]     11: <% end %>
2020-09-22T03:42:18.459082+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf]
2020-09-22T03:42:18.459083+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042cf] app/views/comments/index.html.erb:8
2020-09-22T03:42:18.459389+00:00 heroku[router]: at=info method=GET path="/recipes/1/comments" host=myrailsrecipeapp.herokuapp.com request_id=0304f2e5-aabb-48a2-8038-734c995042cf fwd="174.97.92.123" dyno=web.1 connect=0ms service=12ms status=500 bytes=1827 protocol=https```

cmets/index.html.erb

<% if @recipe %>
  <h1>Comments for <%= @recipe.title%></h1>
<% else %>
  <h1>All Comments</h1>
<% end %>

<ul>
  <% @comments.each do |c|%>
    <li><%= c.user.username%> says "<%= c.content%>" about this recipe: <strong><%= link_to c.recipe.title, recipe_path(c.recipe_id) %></strong></li>
  <% end %>
</ul>

【问题讨论】:

  • 你跑heroku run --exit-code rake db:migrate了吗?

标签: ruby-on-rails heroku erb


【解决方案1】:

您必须在部署到 heroku 后进行迁移。我希望您之前在 gem 文件中进行过更改。 Heroku 正在与 postgres 合作,开发正在使用 sqlite。如果您之前没有进行过更改,它将无法正常工作。

您必须在生产组中添加 postgres gem:

group :production do
  gem 'pg'
end

然后运行 ​​bundle install --without production。现在您可以部署了。完成后再次转到您的终端并输入:

heroku run rake db:migrate

如果没有其他错误,现在它应该可以工作了

【讨论】:

    猜你喜欢
    • 2017-04-09
    • 2015-12-22
    • 2019-04-28
    • 2021-04-30
    • 2015-05-29
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 2019-01-23
    相关资源
    最近更新 更多