diff --git a/README.markdown b/README.markdown index f07e7905..0e3a5625 100644 --- a/README.markdown +++ b/README.markdown @@ -17,9 +17,6 @@ For now, the easiest way to install `ActiveModel::Serializers` is to add this to Then, install it on the command line: $ bundle install - $ rails g serializers:install - -The installation will generate an `app/serializers` directory and create an `ApplicationSerializer` inside it. You can use the `ApplicationSerializer` for common functionality, and to customize the behavior of embedded associations. See more on this later. # Creating a Serializer @@ -31,6 +28,10 @@ This will generate a serializer in `app/serializers/post_serializer.rb` for your $ rails g serializer post +# ApplicationSerializer the global serializer + +All new serializers descend from either ActiveModel::Serializer or from ApplicationSerializer if you create this file in `app/serializers`. This file is no longer required. + # render :json In your controllers, when you use `render :json`, Rails will now first search for a serializer for the object and use it if available. @@ -42,10 +43,14 @@ In your controllers, when you use `render :json`, Rails will now first search fo end end -In this case, Rails will look for a serializer named `PostSerializer`, and if it exists, use it to serialize the `Post`. If it does not exist, Rails will simply call `to_json` on the `@post` object. +In this case, Rails will look for a serializer named `PostSerializer`, and if it exists, use it to serialize the `Post`. This also works with `render_with`, which uses `to_json` under the hood. Also note that any options passed to `render :json` will be passed to your serializer and available as `@options` inside. +## Getting the old version + +If you find that your project is already relying on the old rails to_json change `render :json` to `render :json => @your_object.to_json`. + # Attributes and Associations Once you have a serializer, you can specify which attributes and associations you would like to include in the serialized form.