Reputation: 83
While trying to create a base class using ActiveRestClient
in Rails 4.2.0, I've run into an issue trying to configure settings in a base class and have those inherited by child classes.
class Foo::Base < ActiveRestClient::Base
base_url "https://example.com/api/v1"
username "testuser"
password "testpassword"
request_body_type :json
end
class Foo::Thing < Foo::Base
get :all, "/things"
end
I get no errors but when performing Foo::Thing.all
it throws URI::InvalidURIError
. The same method works if the settings from Foo::Base
are moved into Foo::Thing
.
It also works if the base class modifies the settings directly in the parent class using ActiveRestClient::Base.base_url = "..."
but that is a global change and not ideal.
I have several models that all use the same base settings, so it would make sense to set them in a base class and inherit from it.
Upvotes: 1
Views: 92