在本地,它有效。在Heroku
制作中,我在使用ActiveModelSerializers
时不断收到此错误消息。我使用active_model_serializers (~> 0.10.2)
ArgumentError(缺少要链接的主机!请提供:host参数,设置default_url_options [:host],或将:only_path设置为true):
我已经通读了
我尝试在./app/config/environments/production.rb
Rails.application.configure do
config.action_mailer.default_url_options = { host: 'lit-brushlands-
65490.herokuapp.com' }
end
我已尝试在./app/serializers/application_serializer.rb
中定义它,就像我看到Drifting Ruby在2:30进入video一样。
# ./app/serializers/application_serializer.rb
class ApplicationSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
default_url_options[:host] = 'lit-brushlands-65490.herokuapp.com'
end
我也尝试在./config/application.rb
中定义它,就像Remear建议的那样,将其作为对此pull request ActiveModelSerializers的最后评论。
这是我的堆栈跟踪。我尝试在装饰器中提取用户个人资料照片。
2018-05-29T12:40:31.274554+00:00 app[web.1]: I, [2018-05-29T12:40:31.274447 #4] INFO -- : [b70376bf-4950-4376-bf91-f21a3533e9d3] [active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::Attributes (1766.98ms)
2018-05-29T12:40:31.274941+00:00 app[web.1]: I, [2018-05-29T12:40:31.274854 #4] INFO -- : [b70376bf-4950-4376-bf91-f21a3533e9d3] Completed 500 Internal Server Error in 1877ms (ActiveRecord: 126.0ms)
2018-05-29T12:40:31.276753+00:00 app[web.1]: F, [2018-05-29T12:40:31.276654 #4] FATAL -- : [b70376bf-4950-4376-bf91-f21a3533e9d3]
2018-05-29T12:40:31.276834+00:00 app[web.1]: F, [2018-05-29T12:40:31.276754 #4] FATAL -- : [b70376bf-4950-4376-bf91-f21a3533e9d3] ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
2018-05-29T12:40:31.276923+00:00 app[web.1]: F, [2018-05-29T12:40:31.276835 #4] FATAL -- : [b70376bf-4950-4376-bf91-f21a3533e9d3]
2018-05-29T12:40:31.277014+00:00 app[web.1]: F, [2018-05-29T12:40:31.276930 #4] FATAL -- : [b70376bf-4950-4376-bf91-f21a3533e9d3] app/decorators/user_decorator.rb:13:in `most_recent_profile_photo'
2018-05-29T12:40:31.277017+00:00 app[web.1]: [b70376bf-4950-4376-bf91-f21a3533e9d3] app/serializers/user_serializer.rb:11:in `profile_photo_url'
2018-05-29T12:40:31.277019+00:00 app[web.1]: [b70376bf-4950-4376-bf91-f21a3533e9d3] app/controllers/v1/posts_controller.rb:10:in `index
答案 0 :(得分:0)
我假设您在AWS中使用carrierwave
。错误可能不会直接来自Serializer
,请检查carrierwave
也许您在开发中使用不同的主机并且需要更改
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'xxx', # required
aws_secret_access_key: 'yyy', # required
region: 'eu-west-1', # optional, defaults to 'us-east-1'
host: 's3.example.com', # optional, defaults to nil
endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = 'name_of_directory' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
答案 1 :(得分:0)
# production.rb
Rails.application.routes.default_url_options[:host] ='lit-brushlands-65490.herokuapp.com'