1

I'm trying to use active_model_serializers to convert an object to JSON. As per this question, I created a file called config/initializers/serializers.rb with the following code:

puts 'Running serializers.rb.'
ActiveModelSerializers.config.adapter = :json_api

I see Running serializers.rb. when resetting the database, but not when running the Rails console. In the console, when I type UserSerializer.new(User.first).as_json, I get {:id=>1, :name=>"Regular User", :created_at=>Thu, 07 Jul 2016 06:03:46 UTC +00:00, :lists=>[{:id=>1, :title=>"Before Wednesday"}]}, which is clearly not JSON. How do I get the as_json method to actually return JSON?

Community
  • 1
  • 1
luther
  • 5,195
  • 1
  • 14
  • 24

1 Answers1

2

UserSerializer.new(User.first).to_json

http://apidock.com/rails/Hash/to_json

fabriciofreitag
  • 2,843
  • 22
  • 26