grape-active_model_serializers icon indicating copy to clipboard operation
grape-active_model_serializers copied to clipboard

Documentation on the ErrorSerializer

Open dja opened this issue 7 years ago • 3 comments

I've tried getting it to serialize ActiveModel errors, but to no avail.

Here's what I've got going on..

I've tried both of these for good measure.

# /api/v1/defaults.rb
error_formatter :json, Grape::Formatter::ActiveModelSerializers
error_formatter :jsonapi, Grape::Formatter::ActiveModelSerializers
# api/v1/users.rb, includes defaults

params do
  requires :id, types: String, desc: 'User ID'
end
route_param :id do
  before do
    @user = User.where(id: params[:id]).first!
  end

  desc 'Update a user'
  params do
    optional :first_name, type: String, desc: 'First Name'
    optional :last_name, type: String, desc: 'Last Name'
    optional :email, type: String, desc: 'Email Address'
  end
  patch do
      @user.update(params)
  end
end

Any suggestions greatly appreciated!

dja avatar Feb 16 '18 00:02 dja

Maybe turn it into a spec and we can take a look?

dblock avatar Feb 18 '18 13:02 dblock

Looks like the PRs for error_formatter being added didn't include a version bump and republish to ruby gems... The latest version published is 1.5.1.

https://github.com/ruby-grape/grape-active_model_serializers/pull/80

dja avatar Feb 27 '18 21:02 dja

Are you saying HEAD has the code that works? If so you can close this.

I opened https://github.com/ruby-grape/grape-active_model_serializers/issues/84 to do a release, hopefully soon.

dblock avatar Feb 28 '18 04:02 dblock