The index method in the controller does not work for the active model serializer

I want to send a response jsoncontaining a collection of my resource bookmarks. For some reason, the active model serializer just doesn't manipulate my json as expected. This gives only the default answer.

Here is my serializer BookmarksSerializerinapp/serializers/bookmarks_serializer.rb

class BookmarksSerializer < ActiveModel::Serializer
  attributes :id, :url, :title
end

and my controller method is inside mine Api::UsersController, which has a filter respond_to :jsonon top

def index
  user = User.find_by(username: params[:username])
  @bookmarks = user.bookmarks
  render json: @bookmarks.to_json
end

Instead of getting only: id,: title and: url, I get the full hash by default

What am I doing wrong? I use the rails 4.1.5github version of the active_model_serializers gem.

gem 'active_model_serializers', github: 'rails-api/active_model_serializers'

FYI: show , . , . ,

+1
2

. 4 , , , . 0-9-stable. :

gem 'active_model_serializers', github: 'rails-api/active_model_serializers', branch: '0-9-stable'

+1

render: json = > @bookmarks, each_serializer: BookmarksSerializer

+1

All Articles