Closed
Description
Hey humans,
Let's say I have
class MessageSerializer < ActiveModel::Serializer
attributes :content
belongs_to :user
end
When I use render json: @message
in the controller I get {:message=>{:content=>"some peoisadfnsaidfnple like wefaefsushi", :user=>{:email=>"hi@example.com"}}}
which is what I'd expect.
However, I'd like to be able to get the same serialization without using render
in the controller.
I couldn't find anything in the docs and the only way around I found is
ActiveModel::Serializer::Adapter::Json.new(MessageSerializer.new(Message.last)).serializable_hash
Is there an easier way of achieving the above?
Cheers!
Metadata
Assignees
Labels
No labels