Closed GuskiS closed 6 years ago
This is my recommended usage now:
render json: { data: UserSerializer.new(current_user).serialize }
I just added some parameters to fix your use case though. I forgot that ActiveSupport expected #as_json and #to_json to take an options argument.
I'm not keen on the idea that a serializer is in some way a stand in for the object (it is one-way converter) but they can be used that way now if it makes things easier.
Btw, just tried adding:
def as_json(data = {})
super()
end
and it seems to be working.
Yeah the issue was my as_json implementation didn't take any arguments.
When I do:
I get
ArgumentError (wrong number of arguments (given 1, expected 0))
there isn't much of stacktrace, but it points to https://github.com/wmakley/simple_serializer/blob/master/lib/simple_serializer.rb#L99However, if I do:
it works just fine.
I tried adding:
to serializer,
data
seems to be{}
🤔