Locally, it works. In Heroku
production, I keep getting this error message when using ActiveModelSerializers
. I've using active_model_serializers (~> 0.10.2)
ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
I've read through
Missing host to link to! Please provide :host parameter or set default_url_options[:host] (ActionView::Template::Error)
Missing host to link to! Please provide the :host parameter, for Rails 4
I've tried defining it in ./app/config/environments/production.rb
Rails.application.configure do
config.action_mailer.default_url_options = { host: 'lit-brushlands-
65490.herokuapp.com' }
end
I've tried defining it in ./app/serializers/application_serializer.rb
like I see Drifting Ruby do it at 2:30 into the 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
I've also tried defining it in ./config/application.rb
like how Remear suggested to do it as the last comment on this pull request of ActiveModelSerializers.
Here's my stack trace. I try fetching a users profile photo in a decorator.
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
I assume you are using carrierwave
with AWS. It's possible the error is not coming directly from Serializer
, check your setttings for carrierwave
Maybe you are using different host in development and that needs change
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
I am not using ActiveModelSerializers
but I had the same error but this did not solve it for me:
include Rails.application.routes.url_helpers
I fixed it by updating my production environment file as follows:
# production.rb
Rails.application.routes.default_url_options[:host] ='lit-brushlands-65490.herokuapp.com'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With