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

No serializer found for resource #1250

Closed
marucjmar opened this issue Oct 7, 2015 · 12 comments
Closed

No serializer found for resource #1250

marucjmar opened this issue Oct 7, 2015 · 12 comments

Comments

@marucjmar
Copy link

AMS version -> 0.10.0.rc3
Image of Yaktocat

AMS version -> 0.9.3 All ok

@NullVoxPopuli
Copy link
Contributor

can you post the model and serializer you expect it to use, and the controller action which tries to render with the serializer?
thanks!

@bf4
Copy link
Member

bf4 commented Oct 7, 2015

also, the full backtrace, ruby version, rand rails version (this should really all be in CONTRIBUTING.md but appears to be missing)

@bf4
Copy link
Member

bf4 commented Oct 7, 2015

This is an expected situation for primitive associations, so we'll need more info to see why you're getting it. (It's handled later)

@marucjmar
Copy link
Author

model

class Picture < ActiveRecord::Base
    validates :title, presence: true, length: {minimum: 5 , maximum: 100 }
    validates :url, presence: true
    validates :user_id, presence: true

    has_many :picture_comments
    belongs_to :user
end

Serializer

class PicturesSerializer < ActiveModel::Serializer
   attributes :id, :title, :url, :user_id, :rating,  :created_at

   has_one :user, serializer: SimpleUserSerializer
end

SimpleUserSerializer

class SimpleUserSerializer < ActiveModel::Serializer
   attributes  :id, :nick, :avatar

end

grape controller

module API
  module V1
    class Pictures < Grape::API
      include API::V1::Defaults

      format :json
      formatter :json, Grape::Formatter::ActiveModelSerializers

      resource :pictures do
        desc "Return pictures paginate"
        paginate per_page: 10, max_per_page: 200
        params do
          optional :top, type: Boolean
          optional :from_date, type: Date
          optional :to_date, type: Date
        end
        get "", root: :pictures, each_serializer: PicturesSerializer do
           ...
            pictures =  Picture.all.order(created_at: :desc)
            paginate pictures 
          end
        end
...

@bf4
Copy link
Member

bf4 commented Oct 7, 2015

still missing #1250 (comment)

also, the full backtrace, ruby version, and rails version (this should really all be in CONTRIBUTING.md but appears to be missing)

the fact that you're using Grape and not Rails is incredibly important to share. The gem you're using is out of date https://github.com/jrhe/grape-active_model_serializers/blob/ca9c8faaa99727300ff21419aa20471ac27eed42/lib/grape-active_model_serializers/formatter.rb#L15-L25

@bf4
Copy link
Member

bf4 commented Oct 7, 2015

I'm going to close this, since it's a grape gem issue. I'll help you with a PR there if you want, or even a monkey patch

@bf4 bf4 closed this as completed Oct 7, 2015
@bf4
Copy link
Member

bf4 commented Oct 7, 2015

@rails-api/ams I'd be up for adding a grape integration to AMS. It would be easier for end-users to track changes, and shouldn't include much code or otherwise involve much

@bf4 bf4 mentioned this issue Oct 8, 2015
@dripisforever
Copy link

is there any news? @marucjmar

@asampatoor
Copy link

I am getting the same issue. Can anyone help me with this?

@marucjmar
Copy link
Author

@strivemag, @asampatoor Too old topic, I do not remember

@LeonidFilbert
Copy link

@strivemag, @asampatoor add this to your config.ru: require 'grape-active_model_serializers'

@asampatoor
Copy link

@LeonidFilbert Thank you for the response. But that didn't fix the issue.

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

6 participants