Skip to content
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

ApplicationSerializer not picked up by generator #1890

Closed
ganlron opened this issue Aug 25, 2016 · 4 comments
Closed

ApplicationSerializer not picked up by generator #1890

ganlron opened this issue Aug 25, 2016 · 4 comments

Comments

@ganlron
Copy link

ganlron commented Aug 25, 2016

Expected behavior vs actual behaviour

I've created an ApplicationSerializer in app/serializers/application_serializer.rb and was expecting rails g serializer foo to inherit from this, but it still defaults to ActiveModel::Serializer.

I can get around this by passing ApplicationSerializer with --parent and it works, but wasn't expected behaviour

Environment

Rails 5.0.0.1
ruby 2.3.1p112

@bf4
Copy link
Member

bf4 commented Aug 25, 2016

@ganlron which AMS version? I'm unfamiliar with --parent. You ran rails g serializer User --parent ApplicationSerializer?

@bf4
Copy link
Member

bf4 commented Aug 25, 2016

Oh, ha, it's our own option

class_option :parent, type: :string, desc: 'The parent class for the generated serializer'

Looks like it's because the generator checks if the ApplicationSerializer is defined, and it may not have been loaded yet? So, logic there could be better?

@ganlron
Copy link
Author

ganlron commented Aug 25, 2016

LOL ya, was your option :)

I was trying to figure out how it would be loaded in the generator flow. Maybe the flow has changed for Rails 5, as simply creating an Application Serializer doesn't seem to cut it anymore.

@bf4
Copy link
Member

bf4 commented Aug 26, 2016

I'm pretty sure you could fix this by changing the defined? check

      def parent_class_name
        options[:parent] or  ::ApplicationSerializer.name
      rescue NameError
          'ActiveModel::Serializer'
      end

richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 5, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
richmolj pushed a commit to richmolj/active_model_serializers that referenced this issue Sep 16, 2016
ApplicationSerializer could exist, but not be loaded. So, we check
existence by looking at the filesystem instead of defined?.

Fixes rails-api#1890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants