-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true #573
Comments
Note, this is because I'm using a url method, such as some_url from routes in my serializer. |
This is certainly a bug. Which version of AMS are you using? |
After jumping from Rails 4.1.5 to 4.2.0.beta1 we started seeing this as well on AMS 0.8.1. Still digging around to see what might be causing the issue. We see it when a serializer is being used outside of a request. An example of a spec that would fail: # Bug(id: integer, name: string, created_at: datetime, updated_at: datetime)
class BugSerializer < ActiveModel::Serializer
attributes :id, :name, :url
def url
bug_url(id: object.id)
end
end
class BugsController < ApplicationController
def index
render json: Bug.first
end
end
class BugsControllerTest < ActionController::TestCase
test "when the model is being serialized in a request" do
get :index
assert_equal 200, response.status
end
test "when serializing manually" do
get :index
# This will raise the ArgumentError
expected = BugSerializer.new(Bug.first).to_json
assert_equal expected, response.body
end
end Still digging to see what the issue is. This attempt to work-around fails: I'll update if I have time to dig some more -- hope the additional info helps! |
Thanks! |
Rails 4.1.6, AMS 8.2. |
Issue still seems to be occurring on Rails 4.2.0, AMS 0.9.3, but for me it's occurring in a regular controller. Using the workaround above results in an error "undefined method `build_json' for SomeSerializer:class" |
I think upgrading to 0.8.3 fixed this for us with Rails 4.2, but code has changed so I can't check anymore. Can someone verify? |
Still exists in 0.9.x branch (though it looks more like a Rails issue than AMS). Looks like if I have a database field that ends with EDIT Yep, I had routes called "terms_url" and "privacy_url" so looks like there was some kind of clash there. Wonder if there's a Rails way to enforce that app urls are defined outside of a global namespace? That's pretty nasty the way it is. |
@typeoneerror so, you're good? perhaps set a key for the |
@bf4 I'm good. What do you mean by "set a key for the _url attributes?" |
This also seems to be an issue on 0.10.0.rc3 |
Rails url_helpers were added to 0.10 by #1550. |
Getting this error even when I set:
ActiveModel::Serializer.default_host_options[:host] = '127.0.0.1:3000'
while running tests
The text was updated successfully, but these errors were encountered: