{"id":5901,"date":"2014-04-08T02:06:03","date_gmt":"2014-04-08T02:06:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/08\/problem-about-active-model-serializers-collection-of-common-programming-errors\/"},"modified":"2014-04-08T02:06:03","modified_gmt":"2014-04-08T02:06:03","slug":"problem-about-active-model-serializers-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/08\/problem-about-active-model-serializers-collection-of-common-programming-errors\/","title":{"rendered":"problem about active-model-serializers-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e990c2bcb4dfb7fd0c398098da9bca59?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntimpone<br \/>\nruby-on-rails ruby-on-rails-3.2 paperclip active-model-serializers<br \/>\nI have an asset model class and it has different sizes using paperclip 3.5.2:class AssetSerializer &lt; ActiveModel::Serializerattributes :id, :asset # works fine# would like to output small but don&#8217;t seem to be able to#attributes :id, :asset, :asset(:small) endIt&#8217;s a bit confusing because Paperclip uses the name class and the model is called class (ok really confusing). I get the following error:\/Users\/jt\/repos\/rails\/app\/serializers\/asset_serializer.rb:2: syntax error, unexpected &#8216;(&#8216;, expectin<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/79bb59075981dfc135f3a76e7d01739b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nshicholas<br \/>\nruby-on-rails-4 active-model-serializers<br \/>\nI have a serializerclass FundingSerializer &lt; ActiveModel::Serializerattributes :id, has_one :userhas_one :tournamentembed :ids, include: true endThat initializes with the proper associationsFundingSerializer.new(Funding.first).to_jsonyields&#8221;{\\&#8221;users\\&#8221;:[{\\&#8221;id\\&#8221;:2,\\&#8221;first_name\\&#8221;:\\&#8221;Nick\\&#8221;}],\\&#8221;tournaments\\&#8221;:[{\\&#8221;id\\&#8221;:1,\\&#8221;end_date\\&#8221;:\\&#8221;2013-07-21T23:18:54.981Z\\&#8221;,\\&#8221;start_date\\&#8221;:\\&#8221;2013-07-14T23:18:54.980Z\\&#8221;}],\\&#8221;funding\\&#8221;:{\\&#8221;id\\&#8221;:1}}&#8221;but, FundingSerializer.new(Funding.all).to_jsongets this error.undefi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/354d279a4def71b4541964105311709c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJesper<br \/>\nruby-on-rails active-model-serializers<br \/>\nI&#8217;ve got two models:class Subject &lt; ActiveRecord::Basehas_many :user_combinationshas_ancestry endclass UserCombination &lt; ActiveRecord::Basebelongs_to :stagebelongs_to :subjectbelongs_to :user endAnd two serializers:class UserCombinationSerializer &lt; ActiveModel::Serializerattributes :idbelongs_to :stagebelongs_to :subject endclass SubjectSerializer &lt; ActiveModel::Serializerattributes :id, :name, :description, :subjectsdef include_subjects?object.is_root?enddef subjectsobject.subtreeen<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0fff9ca11ef44ea536976fcab499f8fe?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGawyn<br \/>\nactive-model-serializers<br \/>\nWhen rendering the json of a model with nested associations I get the following error:undefined method `serializable_hash&#8217; for #&lt;ActiveModel::ArraySerializer:0x007fe761592d88&gt;This is my code:class EventSerializer &lt; ActiveModel::Serializerattributes :id, :name, :datehas_many :markets endclass MarketSerializer &lt; ActiveModel::Serializerattributes :id, :bet_limit_timehas_many :options endclass OptionSerializer &lt; ActiveModel::Serializerattributes :id, :name, :odds endThe error appears<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7f55a2ae375faa299f41ee515f4cb8df?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1938736<br \/>\nruby-on-rails ember.js active-model-serializers<br \/>\nI&#8217;m trying to sideload data in active_model_serializer for an Ember application and get a NoMethodError when I attempt to include the objects:undefined method `object&#8217; for #Email:0x00000100d33d20It only happens when :include =&gt; true is set, like this:class ContactSerializer &lt; ActiveModel::Serializerembed :ids, :include =&gt; trueattributes :first_name, :last_namehas_many :emails endMy models look like this:class Contact &lt; ActiveRecord::Baseattr_accessible :first_name, :last_name, :company,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fe981ba1d30b3b54836d158ce528416c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbenburton<br \/>\nember.js ember-data active-model-serializers<br \/>\nI have a few models in Rails that look something like this:class Issue &lt; ActiveRecord::Basebelongs_to :reporter, class_name: &#8216;User&#8217;belongs_to :assignee, class_name: &#8216;User&#8217;has_many :comments endclass User &lt; ActiveRecord::Base endclass Comment &lt; ActiveRecord::Base endwith serializers like so:class IssueSerializer &lt; ActiveModel::Serializerattributes :idembed :ids, include: truehas_one :reporter, :embed =&gt; :idshas_one :assignee, :embed =&gt; :ids endclass UserSerializer &lt; ActiveMod<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>timpone ruby-on-rails ruby-on-rails-3.2 paperclip active-model-serializers I have an asset model class and it has different sizes using paperclip 3.5.2:class AssetSerializer &lt; ActiveModel::Serializerattributes :id, :asset # works fine# would like to output small but don&#8217;t seem to be able to#attributes :id, :asset, :asset(:small) endIt&#8217;s a bit confusing because Paperclip uses the name class and the model [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5901","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5901"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5901\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}