Closed ivan-garanin closed 7 years ago
Here is my base
grape file
module Nsi
class API < Grape::API
format :json
formatter :json, Grape::Formatter::ActiveModelSerializers
mount Nsi::DictionaryResource
mount Nsi::ParameterResource
mount Nsi::DictionaryParameterResource
add_swagger_documentation :format => :json,
:hide_documentation_path => true,
:mount_path => 'swagger_doc'
end
end
same error without option
each_serialize: DictionarySerializer
Looks like i have got anonymous class a = Class.new; a.name => nil
in Grape::ActiveModelSerializers::SerializerResolver
in instance initialization something like Grape::ActiveModelSerializers::SerializerResolver.new(Class.new, opts)
hm... I already have got it there...
module Grape
module Formatter
module ActiveModelSerializers
class << self
def call(resource, env)
# !!!! resource.class.name => nil, resource.class => #<Class:0x005...>
options = build_options(resource, env)
serializer = fetch_serializer(resource, options)
if serializer
::ActiveModelSerializers::Adapter.create(
serializer, options
).to_json
else
Grape::Formatter::Json.call(resource, env)
end
end
def build_options(resource, env)
Grape::ActiveModelSerializers::OptionsBuilder.new(
resource, env
).options
end
def fetch_serializer(resource, options)
Grape::ActiveModelSerializers::SerializerResolver.new(
resource, options
).serializer
end
end
end
end
end
hm... I need help guys :(' What I'm doing wrong?
Hi @ivan-garanin, is there a project that I would be able to reproduce this error in? If I can replicate the error, I can look into patching it
Hi @drn , I'll publish on github my cutted project for you tomorrow.
@drn, I made example app(with all same configs/settings and so on) https://github.com/ivan-garanin/example-for-grape_active_model_serializer check readme to launch it faster
Thanks for providing that project, @ivan-garanin
I dug into our source code via your project and it looks like neither this gem or active_model_serializers
have great support for non-ActiveRecord ORMs. Both gems key off of collection resources responding to a to_ary
method that ActiveRecord has implemented for collections, but Sequel does not.
That said, I implemented some basic support for sequel that you can try out. https://github.com/ruby-grape/grape-active_model_serializers/pull/74
I tested this against your project:
gem 'grape-active_model_serializers',
github: 'ruby-grape/grape-active_model_serializers',
branch: 'support-sequel'
Let me know if it works for you!
@drn thank you!
👍 worked? ill get that merged in over the next few days and release a new gem version
yea, everything is OK, ty for help, ping me when release ll be ready and I'd remove that ugly line from Gemfile)
Hello,
Im using Grape, sequel, rake and grape-active_model_serializers( no rails ) for my little application.
Here is code of problem place
When im trying to take list of dictionaries im taking such error
Here is backtrace
All other routes(get(id), patch, all other) which are working with single record(not array) are fine.
Could you help me with this issue?