ruby on rails - Adding a Computed Attribute to ActiveResource Resource -


what i'm trying add attribute activeresource resource computer based on other attributes created servers response.

further complicating things attributes computation depends on part of has_many association has_many: items.

what i'd happen when u = user.find(123) called items retrieved , attribute added user based on computation, example u.blue_item_count.

the new attribute need appear when object serialized xml or json. instance u serialize {"id":1, "name":"bob", "blue_item_count":21 }.

thanks

just define method on user object uses items association. example:

class user < activerecord::base     has_many :items      def blue_item_count         items.each |item|             ...         end     end end 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -