Generate id method on Ruby 1.8.

Because object_id and id went through some flux, it's best to tell 1.8
specifically what we mean.

Closes #127.
This commit is contained in:
Steve Klabnik
2013-03-19 14:53:08 -07:00
parent 145b6d499d
commit c129ae2016
4 changed files with 32 additions and 3 deletions

View File

@@ -4,5 +4,16 @@ class <%= class_name %>Serializer < <%= parent_class_name %>
<% association_names.each do |attribute| -%>
has_one :<%= attribute %>
<% end -%>
<% if generate_id_method %>
# due to the difference between 1.8 and 1.9 with respect to #id and
# #object_id, we reccomend that if you wish to serialize id columns, you
# do this. Feel free to remove this if you don't feel that it's appropriate.
#
# For more: https://github.com/rails-api/active_model_serializers/issues/127
def id
object.read_attribute_for_serialization(:id)
end
<% end -%>
end
<% end -%>