在 Heroku 上部署 Rails API 在进行开发时抛出内部服务器错误 (500)
Deployed Rails API on Heroku throws internal server error (500) while it works on development
我在 Heroku 上部署了 Rails API(Rails API 不是使用 rails new <app-name> --api
创建的,而是 Rails 应用程序,我从中创建了一个 API)。
在 Heroku 上部署时,Rails API 不起作用并抛出内部服务器错误状态 500。
我曾尝试使用邮递员和浏览器联系我的 API,但我收到 JSON 内部服务器错误输出。
上述JSON响应是向my-app-name.herokuapp.com/api/v1/foods
发送请求的结果
我应该提一下,我尝试 heroku run rails console
查看我的数据库是否正确播种,我得到了我应该正确获得的所有数据。
这里我在尝试向上面提到的url发送请求后复制了heroku logs --tail
的结果:
2019-06-18T19:45:53.619745+00:00 heroku[web.1]: State changed from starting to up
2019-06-18T19:45:55.010890+00:00 app[web.1]: => Booting Puma
2019-06-18T19:45:55.010918+00:00 app[web.1]: => Rails 5.2.3 application starting in production
2019-06-18T19:45:55.010920+00:00 app[web.1]: => Run `rails server -h` for more startup options
2019-06-18T19:45:55.010922+00:00 app[web.1]: Puma starting in single mode...
2019-06-18T19:45:55.010924+00:00 app[web.1]: * Version 3.12.1 (ruby 2.6.2-p47), codename: Llamas in Pajamas
2019-06-18T19:45:55.010926+00:00 app[web.1]: * Min threads: 5, max threads: 5
2019-06-18T19:45:55.010927+00:00 app[web.1]: * Environment: production
2019-06-18T19:45:55.010929+00:00 app[web.1]: * Listening on tcp://0.0.0.0:53860
2019-06-18T19:45:55.010930+00:00 app[web.1]: Use Ctrl-C to stop
2019-06-18T19:45:55.010940+00:00 app[web.1]: I, [2019-06-18T19:45:55.010760 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Started GET "/api/v1/foods" for 50.64.98.60 at 2019-06-18 19:45:55 +0000
2019-06-18T19:45:55.013576+00:00 app[web.1]: I, [2019-06-18T19:45:55.013496 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Processing by Api::V1::FoodsController#index as JSON
2019-06-18T19:45:55.099003+00:00 app[web.1]: D, [2019-06-18T19:45:55.098851 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Food Load (2.5ms) SELECT "foods".* FROM "foods" ORDER BY "foods"."created_at" DESC
2019-06-18T19:45:55.141862+00:00 app[web.1]: D, [2019-06-18T19:45:55.141763 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 13], ["LIMIT", 1]]
2019-06-18T19:45:55.175064+00:00 app[web.1]: D, [2019-06-18T19:45:55.174961 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.177292+00:00 app[web.1]: D, [2019-06-18T19:45:55.177228 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.178159+00:00 app[web.1]: D, [2019-06-18T19:45:55.178086 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.179086+00:00 app[web.1]: D, [2019-06-18T19:45:55.179015 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.181104+00:00 app[web.1]: D, [2019-06-18T19:45:55.181021 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.182066+00:00 app[web.1]: D, [2019-06-18T19:45:55.182006 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.183364+00:00 app[web.1]: D, [2019-06-18T19:45:55.183305 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.184020+00:00 app[web.1]: D, [2019-06-18T19:45:55.183965 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.185703+00:00 app[web.1]: D, [2019-06-18T19:45:55.185634 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.186348+00:00 app[web.1]: D, [2019-06-18T19:45:55.186279 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.187878+00:00 app[web.1]: D, [2019-06-18T19:45:55.187804 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.189597+00:00 app[web.1]: D, [2019-06-18T19:45:55.189533 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.190234+00:00 app[web.1]: D, [2019-06-18T19:45:55.190175 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 13], ["LIMIT", 1]]
2019-06-18T19:45:55.191655+00:00 app[web.1]: D, [2019-06-18T19:45:55.191587 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.192344+00:00 app[web.1]: D, [2019-06-18T19:45:55.192275 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.194231+00:00 app[web.1]: D, [2019-06-18T19:45:55.194164 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 16], ["LIMIT", 1]]
2019-06-18T19:45:55.195760+00:00 app[web.1]: D, [2019-06-18T19:45:55.195683 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.197667+00:00 app[web.1]: D, [2019-06-18T19:45:55.197600 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.198344+00:00 app[web.1]: D, [2019-06-18T19:45:55.198264 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.208444+00:00 app[web.1]: D, [2019-06-18T19:45:55.208360 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] ActiveStorage::Attachment Load (1.5ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = AND "active_storage_attachments"."record_type" = AND "active_storage_attachments"."name" = [["record_id", 20], ["record_type", "Food"], ["name", "pictures"]]
2019-06-18T19:45:55.278745+00:00 heroku[router]: at=info method=GET path="/api/v1/foods" host=cookme-app-api.herokuapp.com request_id=1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c fwd="50.64.98.60" dyno=web.1 connect=0ms service=270ms status=500 bytes=257 protocol=http
2019-06-18T19:45:55.264309+00:00 app[web.1]: D, [2019-06-18T19:45:55.264204 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] ActiveStorage::Blob Load (1.5ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = [["id", 37]]
2019-06-18T19:45:55.273452+00:00 app[web.1]: I, [2019-06-18T19:45:55.273361 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::Attributes (147.01ms)
2019-06-18T19:45:55.273676+00:00 app[web.1]: I, [2019-06-18T19:45:55.273619 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Completed 500 Internal Server Error in 260ms (ActiveRecord: 53.5ms)
2019-06-18T19:45:55.274332+00:00 app[web.1]: F, [2019-06-18T19:45:55.274278 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c]
2019-06-18T19:45:55.274379+00:00 app[web.1]: F, [2019-06-18T19:45:55.274335 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
2019-06-18T19:45:55.274423+00:00 app[web.1]: F, [2019-06-18T19:45:55.274381 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c]
2019-06-18T19:45:55.274474+00:00 app[web.1]: F, [2019-06-18T19:45:55.274433 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:31:in `block in pictures'
2019-06-18T19:45:55.274476+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:25:in `map'
2019-06-18T19:45:55.274477+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:25:in `pictures'
2019-06-18T19:45:55.274479+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/controllers/api/v1/foods_controller.rb:12:in `index'
如错误提示:
ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
您需要在生产配置中添加默认主机:
config/environments/production.rb
Rails.application.routes.default_url_options = { host: "your heroku domain" }
希望对您有所帮助。
我在 Heroku 上部署了 Rails API(Rails API 不是使用 rails new <app-name> --api
创建的,而是 Rails 应用程序,我从中创建了一个 API)。
在 Heroku 上部署时,Rails API 不起作用并抛出内部服务器错误状态 500。
我曾尝试使用邮递员和浏览器联系我的 API,但我收到 JSON 内部服务器错误输出。
上述JSON响应是向my-app-name.herokuapp.com/api/v1/foods
发送请求的结果
我应该提一下,我尝试 heroku run rails console
查看我的数据库是否正确播种,我得到了我应该正确获得的所有数据。
这里我在尝试向上面提到的url发送请求后复制了heroku logs --tail
的结果:
2019-06-18T19:45:53.619745+00:00 heroku[web.1]: State changed from starting to up
2019-06-18T19:45:55.010890+00:00 app[web.1]: => Booting Puma
2019-06-18T19:45:55.010918+00:00 app[web.1]: => Rails 5.2.3 application starting in production
2019-06-18T19:45:55.010920+00:00 app[web.1]: => Run `rails server -h` for more startup options
2019-06-18T19:45:55.010922+00:00 app[web.1]: Puma starting in single mode...
2019-06-18T19:45:55.010924+00:00 app[web.1]: * Version 3.12.1 (ruby 2.6.2-p47), codename: Llamas in Pajamas
2019-06-18T19:45:55.010926+00:00 app[web.1]: * Min threads: 5, max threads: 5
2019-06-18T19:45:55.010927+00:00 app[web.1]: * Environment: production
2019-06-18T19:45:55.010929+00:00 app[web.1]: * Listening on tcp://0.0.0.0:53860
2019-06-18T19:45:55.010930+00:00 app[web.1]: Use Ctrl-C to stop
2019-06-18T19:45:55.010940+00:00 app[web.1]: I, [2019-06-18T19:45:55.010760 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Started GET "/api/v1/foods" for 50.64.98.60 at 2019-06-18 19:45:55 +0000
2019-06-18T19:45:55.013576+00:00 app[web.1]: I, [2019-06-18T19:45:55.013496 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Processing by Api::V1::FoodsController#index as JSON
2019-06-18T19:45:55.099003+00:00 app[web.1]: D, [2019-06-18T19:45:55.098851 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Food Load (2.5ms) SELECT "foods".* FROM "foods" ORDER BY "foods"."created_at" DESC
2019-06-18T19:45:55.141862+00:00 app[web.1]: D, [2019-06-18T19:45:55.141763 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 13], ["LIMIT", 1]]
2019-06-18T19:45:55.175064+00:00 app[web.1]: D, [2019-06-18T19:45:55.174961 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.177292+00:00 app[web.1]: D, [2019-06-18T19:45:55.177228 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.178159+00:00 app[web.1]: D, [2019-06-18T19:45:55.178086 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.179086+00:00 app[web.1]: D, [2019-06-18T19:45:55.179015 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.181104+00:00 app[web.1]: D, [2019-06-18T19:45:55.181021 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.182066+00:00 app[web.1]: D, [2019-06-18T19:45:55.182006 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.183364+00:00 app[web.1]: D, [2019-06-18T19:45:55.183305 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.184020+00:00 app[web.1]: D, [2019-06-18T19:45:55.183965 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.185703+00:00 app[web.1]: D, [2019-06-18T19:45:55.185634 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.186348+00:00 app[web.1]: D, [2019-06-18T19:45:55.186279 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.187878+00:00 app[web.1]: D, [2019-06-18T19:45:55.187804 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.189597+00:00 app[web.1]: D, [2019-06-18T19:45:55.189533 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.190234+00:00 app[web.1]: D, [2019-06-18T19:45:55.190175 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 13], ["LIMIT", 1]]
2019-06-18T19:45:55.191655+00:00 app[web.1]: D, [2019-06-18T19:45:55.191587 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 17], ["LIMIT", 1]]
2019-06-18T19:45:55.192344+00:00 app[web.1]: D, [2019-06-18T19:45:55.192275 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.194231+00:00 app[web.1]: D, [2019-06-18T19:45:55.194164 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 16], ["LIMIT", 1]]
2019-06-18T19:45:55.195760+00:00 app[web.1]: D, [2019-06-18T19:45:55.195683 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.197667+00:00 app[web.1]: D, [2019-06-18T19:45:55.197600 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 14], ["LIMIT", 1]]
2019-06-18T19:45:55.198344+00:00 app[web.1]: D, [2019-06-18T19:45:55.198264 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT [["id", 15], ["LIMIT", 1]]
2019-06-18T19:45:55.208444+00:00 app[web.1]: D, [2019-06-18T19:45:55.208360 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] ActiveStorage::Attachment Load (1.5ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = AND "active_storage_attachments"."record_type" = AND "active_storage_attachments"."name" = [["record_id", 20], ["record_type", "Food"], ["name", "pictures"]]
2019-06-18T19:45:55.278745+00:00 heroku[router]: at=info method=GET path="/api/v1/foods" host=cookme-app-api.herokuapp.com request_id=1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c fwd="50.64.98.60" dyno=web.1 connect=0ms service=270ms status=500 bytes=257 protocol=http
2019-06-18T19:45:55.264309+00:00 app[web.1]: D, [2019-06-18T19:45:55.264204 #4] DEBUG -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] ActiveStorage::Blob Load (1.5ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = [["id", 37]]
2019-06-18T19:45:55.273452+00:00 app[web.1]: I, [2019-06-18T19:45:55.273361 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] [active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::Attributes (147.01ms)
2019-06-18T19:45:55.273676+00:00 app[web.1]: I, [2019-06-18T19:45:55.273619 #4] INFO -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] Completed 500 Internal Server Error in 260ms (ActiveRecord: 53.5ms)
2019-06-18T19:45:55.274332+00:00 app[web.1]: F, [2019-06-18T19:45:55.274278 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c]
2019-06-18T19:45:55.274379+00:00 app[web.1]: F, [2019-06-18T19:45:55.274335 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
2019-06-18T19:45:55.274423+00:00 app[web.1]: F, [2019-06-18T19:45:55.274381 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c]
2019-06-18T19:45:55.274474+00:00 app[web.1]: F, [2019-06-18T19:45:55.274433 #4] FATAL -- : [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:31:in `block in pictures'
2019-06-18T19:45:55.274476+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:25:in `map'
2019-06-18T19:45:55.274477+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/serializers/food_collection_serializer.rb:25:in `pictures'
2019-06-18T19:45:55.274479+00:00 app[web.1]: [1bcb1fe7-acf5-44e0-95bc-aa20d5fd685c] app/controllers/api/v1/foods_controller.rb:12:in `index'
如错误提示:
ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
您需要在生产配置中添加默认主机:
config/environments/production.rb
Rails.application.routes.default_url_options = { host: "your heroku domain" }
希望对您有所帮助。