DESIGN.textile in active_model_serializers-0.7.0 vs DESIGN.textile in active_model_serializers-0.8.0
- old
+ new
@@ -215,11 +215,11 @@
First, we specified the list of included attributes at the top of the class. This will create an instance method called
+attributes+ that extracts those attributes from the post model.
NOTE: Internally, +ActiveModel::Serializer+ uses +read_attribute_for_serialization+, which defaults to +read_attribute+, which defaults to +send+. So if you're rolling your own models for use with the serializer, you can use simple Ruby accessors for your attributes if you like.
-Next, we use the attributes methood in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
+Next, we use the attributes method in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
earlier. We could also eliminate the +as_json+ method, as +ActiveModel::Serializer+ provides a default +as_json+ method for
us that calls our +serializable_hash+ method and inserts a root. But we can go a step further!
<pre lang="ruby">
class PostSerializer < ActiveModel::Serializer
@@ -352,10 +352,10 @@
h4. Modifying Associations
You can also rename associations if required. Say for example you have an association that
makes sense to be named one thing in your code, but another when data is serialized.
You can use the <code:key</code> option to specify a different name for an association.
-Here is an exmaple:
+Here is an example:
<pre lang="ruby">
class UserSerializer < ActiveModel::Serializer
has_many :followed_posts, :key => :posts
has_one :owned_account, :key => :account