我按照教程构建了一个显示所有产品及其部分细节的应用程序。我成功地完成了这一部分。问题是当我点击链接在另一个页面上显示产品的描述时,它会给出(500)内部服务器错误
以下是代码:
home_controller.rb:
class HomeController < ShopifyApp::AuthenticatedController
def index
@products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
end
def show
@products = ShopifyAPI::Product.find(params[:id])
end
end
index.html.erb:
<% content_for :javascript do %>
<script type="text/javascript">
ShopifyApp.ready(function(){
ShopifyApp.Bar.initialize({
title: "Home",
icon: "<%= asset_path('favicon.ico') %>"
});
});
</script>
<% end %>
<h2>Products</h2>
<ul>
<% @products.each do |product| %>
<p>
<b><%= product.title %><br></b>
ID: <%= product.id %><br>
Vendor: <%= product.vendor %><br>
Created at: <%= product.created_at %><br>
</p>
<li><%= link_to 'Show description', home_show_path(product) %></li>
<br><br>
<% end %>
</ul>
show.html.erb:
<h1><%= @product.title %></h1>
<p>Description: <%= @product.body_html %></p>
heroku日志:
2016-12-28T01:01:25.028806+00:00 app[web.1]: I, [2016-12-28T01:01:25.028728 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Processing by HomeController#index as HTML
2016-12-28T01:01:25.028921+00:00 app[web.1]: I, [2016-12-28T01:01:25.028865 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Parameters: {"hmac"=>"df343ac1be8d47fc346c85012e46870a3d1d2c7d593259d6a7e5e2e4be2a60d6", "protocol"=>"https://", "shop"=>"gels-store.myshopify.com", "timestamp"=>"1482886883"}
2016-12-28T01:01:25.099398+00:00 app[web.1]: D, [2016-12-28T01:01:25.099299 #4] DEBUG -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Shop Load (1.4ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2016-12-28T01:01:25.550140+00:00 app[web.1]: I, [2016-12-28T01:01:25.550053 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Rendered home/index.html.erb within layouts/embedded_app (7.2ms)
2016-12-28T01:01:25.542213+00:00 app[web.1]: I, [2016-12-28T01:01:25.542094 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Rendering home/index.html.erb within layouts/embedded_app
2016-12-28T01:01:25.553973+00:00 app[web.1]: I, [2016-12-28T01:01:25.553914 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Rendered layouts/_flash_messages.html.erb (0.8ms)
2016-12-28T01:01:25.554749+00:00 app[web.1]: I, [2016-12-28T01:01:25.554669 #4] INFO -- : [6a2e2c9e-b81e-4ad4-91fc-465c54f339f4] Completed 200 OK in 526ms (Views: 13.7ms | ActiveRecord: 21.7ms)
2016-12-28T01:01:25.569551+00:00 heroku[router]: at=info method=GET path="/?hmac=df343ac1be8d47fc346c85012e46870a3d1d2c7d593259d6a7e5e2e4be2a60d6&protocol=https%3A%2F%2F&shop=gels-store.myshopify.com×tamp=1482886883" host=angelstore.herokuapp.com request_id=6a2e2c9e-b81e-4ad4-91fc-465c54f339f4 fwd="222.127.11.170" dyno=web.1 connect=0ms service=544ms status=200 bytes=3372
2016-12-28T01:01:29.415828+00:00 app[web.1]: I, [2016-12-28T01:01:29.415735 #4] INFO -- : [67b7923f-112d-499e-8ee4-76afe17220ab] Started GET "/home/show.7867909648" for 222.127.11.170 at 2016-12-28 01:01:29 +0000
2016-12-28T01:01:29.417488+00:00 app[web.1]: I, [2016-12-28T01:01:29.417421 #4] INFO -- : [67b7923f-112d-499e-8ee4-76afe17220ab] Processing by HomeController#show as
2016-12-28T01:01:29.426318+00:00 app[web.1]: D, [2016-12-28T01:01:29.426226 #4] DEBUG -- : [67b7923f-112d-499e-8ee4-76afe17220ab] Shop Load (2.6ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2016-12-28T01:01:29.601847+00:00 app[web.1]: I, [2016-12-28T01:01:29.601755 #4] INFO -- : [67b7923f-112d-499e-8ee4-76afe17220ab] Completed 500 Internal Server Error in 184ms (ActiveRecord: 2.6ms)
2016-12-28T01:01:29.603340+00:00 app[web.1]: F, [2016-12-28T01:01:29.603284 #4] FATAL -- : [67b7923f-112d-499e-8ee4-76afe17220ab]
2016-12-28T01:01:29.603452+00:00 app[web.1]: F, [2016-12-28T01:01:29.603370 #4] FATAL -- : [67b7923f-112d-499e-8ee4-76afe17220ab] ActiveResource::ResourceNotFound (Failed. Response code = 404. Response message = Not Found.):
2016-12-28T01:01:29.603537+00:00 app[web.1]: F, [2016-12-28T01:01:29.603474 #4] FATAL -- : [67b7923f-112d-499e-8ee4-76afe17220ab]
2016-12-28T01:01:29.603653+00:00 app[web.1]: F, [2016-12-28T01:01:29.603603 #4] FATAL -- : [67b7923f-112d-499e-8ee4-76afe17220ab] app/controllers/home_controller.rb:13:in `show'
2016-12-28T01:01:29.617184+00:00 heroku[router]: at=info method=GET path="/home/show.7867909648" host=angelstore.herokuapp.com request_id=67b7923f-112d-499e-8ee4-76afe17220ab fwd="222.127.11.170" dyno=web.1 connect=0ms service=191ms status=500 bytes=1669
2016-12-28T01:17:34.584890+00:00 app[web.1]: I, [2016-12-28T01:17:34.584834 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Processing by HomeController#index as HTML
2016-12-28T01:17:34.582622+00:00 app[web.1]: I, [2016-12-28T01:17:34.582517 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Started GET "/?hmac=0357daa86308275954f0df7389e33ab87eb55cdb9091a99466912e12cd5a523f&protocol=https%3A%2F%2F&shop=gels-store.myshopify.com×tamp=1482887853" for 222.127.11.170 at 2016-12-28 01:17:34 +0000
2016-12-28T01:17:34.589609+00:00 app[web.1]: D, [2016-12-28T01:17:34.589524 #4] DEBUG -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Shop Load (1.4ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2016-12-28T01:17:34.585031+00:00 app[web.1]: I, [2016-12-28T01:17:34.584976 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Parameters: {"hmac"=>"0357daa86308275954f0df7389e33ab87eb55cdb9091a99466912e12cd5a523f", "protocol"=>"https://", "shop"=>"gels-store.myshopify.com", "timestamp"=>"1482887853"}
2016-12-28T01:17:35.028248+00:00 heroku[router]: at=info method=GET path="/?hmac=0357daa86308275954f0df7389e33ab87eb55cdb9091a99466912e12cd5a523f&protocol=https%3A%2F%2F&shop=gels-store.myshopify.com×tamp=1482887853" host=angelstore.herokuapp.com request_id=a590ebad-6c05-440b-b645-603cd8bfc079 fwd="222.127.11.170" dyno=web.1 connect=1ms service=441ms status=200 bytes=3372
2016-12-28T01:17:35.008395+00:00 app[web.1]: I, [2016-12-28T01:17:35.008284 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Rendering home/index.html.erb within layouts/embedded_app
2016-12-28T01:17:35.011436+00:00 app[web.1]: I, [2016-12-28T01:17:35.011355 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Rendered home/index.html.erb within layouts/embedded_app (2.7ms)
2016-12-28T01:17:35.013398+00:00 app[web.1]: I, [2016-12-28T01:17:35.013331 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Rendered layouts/_flash_messages.html.erb (0.3ms)
2016-12-28T01:17:35.014512+00:00 app[web.1]: I, [2016-12-28T01:17:35.014462 #4] INFO -- : [a590ebad-6c05-440b-b645-603cd8bfc079] Completed 200 OK in 429ms (Views: 6.2ms | ActiveRecord: 1.4ms)
2016-12-28T01:49:25.658231+00:00 app[web.1]: I, [2016-12-28T01:49:25.658126 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Started GET "/?hmac=9da8f8d814183cb0ac7802880e8848e4bce51c2d864406998d7b8b3f5bc95022&protocol=https%3A%2F%2F&shop=gels-store.myshopify.com×tamp=1482889764" for 222.127.11.170 at 2016-12-28 01:49:25 +0000
2016-12-28T01:49:25.659753+00:00 app[web.1]: I, [2016-12-28T01:49:25.659678 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Processing by HomeController#index as HTML
2016-12-28T01:49:25.659835+00:00 app[web.1]: I, [2016-12-28T01:49:25.659776 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Parameters: {"hmac"=>"9da8f8d814183cb0ac7802880e8848e4bce51c2d864406998d7b8b3f5bc95022", "protocol"=>"https://", "shop"=>"gels-store.myshopify.com", "timestamp"=>"1482889764"}
2016-12-28T01:49:25.671459+00:00 app[web.1]: D, [2016-12-28T01:49:25.671165 #4] DEBUG -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Shop Load (5.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2016-12-28T01:49:26.119086+00:00 heroku[router]: at=info method=GET path="/?hmac=9da8f8d814183cb0ac7802880e8848e4bce51c2d864406998d7b8b3f5bc95022&protocol=https%3A%2F%2F&shop=gels-store.myshopify.com×tamp=1482889764" host=angelstore.herokuapp.com request_id=793b1499-9bcb-4150-ba39-2973ac73500c fwd="222.127.11.170" dyno=web.1 connect=1ms service=465ms status=200 bytes=3372
2016-12-28T01:49:26.107927+00:00 app[web.1]: I, [2016-12-28T01:49:26.107802 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Rendering home/index.html.erb within layouts/embedded_app
2016-12-28T01:49:26.109971+00:00 app[web.1]: I, [2016-12-28T01:49:26.109899 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Rendered home/index.html.erb within layouts/embedded_app (1.9ms)
2016-12-28T01:49:26.111276+00:00 app[web.1]: I, [2016-12-28T01:49:26.111176 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Rendered layouts/_flash_messages.html.erb (0.2ms)
2016-12-28T01:49:26.111884+00:00 app[web.1]: I, [2016-12-28T01:49:26.111817 #4] INFO -- : [793b1499-9bcb-4150-ba39-2973ac73500c] Completed 200 OK in 452ms (Views: 4.2ms | ActiveRecord: 5.5ms)
2016-12-28T01:49:26.522691+00:00 heroku[router]: at=info method=GET path="/assets/application-cbbb5732d70d7094ddba7a7ba5746b6e55093adf1a04b07303a293e1e378e91a.js" host=angelstore.herokuapp.com request_id=e239ea0c-3fc5-4af6-9262-85765448fd2e fwd="222.127.11.170" dyno=web.1 connect=0ms service=8ms status=304 bytes=48
2016-12-28T01:49:35.375345+00:00 app[web.1]: I, [2016-12-28T01:49:35.375220 #4] INFO -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] Started GET "/home/show.7867909648" for 222.127.11.170 at 2016-12-28 01:49:35 +0000
2016-12-28T01:49:35.376624+00:00 app[web.1]: I, [2016-12-28T01:49:35.376568 #4] INFO -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] Processing by HomeController#show as
2016-12-28T01:49:35.380593+00:00 app[web.1]: D, [2016-12-28T01:49:35.380522 #4] DEBUG -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] Shop Load (1.4ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2016-12-28T01:49:35.542679+00:00 app[web.1]: I, [2016-12-28T01:49:35.542574 #4] INFO -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] Completed 500 Internal Server Error in 166ms (ActiveRecord: 1.4ms)
2016-12-28T01:49:35.544843+00:00 app[web.1]: F, [2016-12-28T01:49:35.544775 #4] FATAL -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b]
2016-12-28T01:49:35.544921+00:00 app[web.1]: F, [2016-12-28T01:49:35.544862 #4] FATAL -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] ActiveResource::ResourceNotFound (Failed. Response code = 404. Response message = Not Found.):
2016-12-28T01:49:35.544984+00:00 app[web.1]: F, [2016-12-28T01:49:35.544930 #4] FATAL -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b]
2016-12-28T01:49:35.545049+00:00 app[web.1]: F, [2016-12-28T01:49:35.544997 #4] FATAL -- : [985ea4ca-52de-405d-9dd2-9811f0c0455b] app/controllers/home_controller.rb:13:in `show'
2016-12-28T01:49:35.551115+00:00 heroku[router]: at=info method=GET path="/home/show.7867909648" host=angelstore.herokuapp.com request_id=985ea4ca-52de-405d-9dd2-9811f0c0455b fwd="222.127.11.170" dyno=web.1 connect=0ms service=174ms status=500 bytes=1669