Ruby on rails 部署到Heroku后,注释不起作用
我最近在Heroku上部署了一个应用程序,我的评论有问题。它在开发中工作得很好,但在生产中我得到了下面的错误。看起来Heroku对我的comments.index.html.erb文件(也包括在下面)有问题。有人能告诉我正确的方向吗?它说comments.recipe_id不存在,但我不明白为什么它在开发中可以,但一旦部署就不行了?谢谢Ruby on rails 部署到Heroku后,注释不起作用,ruby-on-rails,heroku,erb,Ruby On Rails,Heroku,Erb,我最近在Heroku上部署了一个应用程序,我的评论有问题。它在开发中工作得很好,但在生产中我得到了下面的错误。看起来Heroku对我的comments.index.html.erb文件(也包括在下面)有问题。有人能告诉我正确的方向吗?它说comments.recipe_id不存在,但我不明白为什么它在开发中可以,但一旦部署就不行了?谢谢 2020-09-22T03:42:18.459074+00:00 app[web.1]: [0304f2e5-aabb-48a2-8038-734c995042
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```
2020-09-22T03:42:18.459074+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]操作视图::模板::错误(PG::未定义列:错误:列注释。配方id不存在
2020-09-22T03:42:18.459075+00:00应用程序[web.1]:第1行:选择“评论”。*从“评论”中的“评论”中选择“配方…”。。。
2020-09-22T03:42:18.459076+00:00应用程序[网站1]:^
2020-09-22T03:42:18.459076+00:00应用程序[web.1]:提示:也许你是想引用“comments.recipe”一栏。
2020-09-22T03:42:18.459077+00:00应用程序[网站1]:):
2020-09-22T03:42:18.459077+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]5:
2020-09-22T03:42:18.459078+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]6:
2020-09-22T03:42:18.459078+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]7:
2020-09-22T03:42:18.459079+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]8:
2020-09-22T03:42:18.459081+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]9:- 说“关于这个配方:
2020-09-22T03:42:18.459082+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]10:
2020-09-22T03:42:18.459082+00:00应用程序[web.1]:[0304f2e5-aabb-48a2-8038-734c995042cf]11:
2020-09-22T03:42:18.459082+00:00应用程序[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[路由器]: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服务=12ms状态=500字节=1827协议=https```
comments/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后,您必须进行迁移。我希望您之前对gem文件进行了更改。heroku正在使用postgres,而开发正在使用sqlite。如果您之前没有进行更改,它将无法工作
在制作组中,您必须添加postgres gem:
group :production do
gem 'pg'
end
然后运行bundle install--无需生产。现在可以部署。完成后,再次转到终端并输入:
heroku run rake db:migrate
现在,如果没有其他错误,它应该可以工作了您是否运行了heroku run——退出代码rake db:migrate?