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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -