{"action":"created","issue":{"url":"https://api.github.com/repos/apotonick/roar/issues/104","labels_url":"https://api.github.com/repos/apotonick/roar/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/apotonick/roar/issues/104/comments","events_url":"https://api.github.com/repos/apotonick/roar/issues/104/events","html_url":"https://github.com/apotonick/roar/issues/104","id":41810449,"number":104,"title":"Collection representation using JSON-API","user":{"login":"intacadmin","id":7503588,"avatar_url":"https://avatars.githubusercontent.com/u/7503588?v=3","gravatar_id":"","url":"https://api.github.com/users/intacadmin","html_url":"https://github.com/intacadmin","followers_url":"https://api.github.com/users/intacadmin/followers","following_url":"https://api.github.com/users/intacadmin/following{/other_user}","gists_url":"https://api.github.com/users/intacadmin/gists{/gist_id}","starred_url":"https://api.github.com/users/intacadmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intacadmin/subscriptions","organizations_url":"https://api.github.com/users/intacadmin/orgs","repos_url":"https://api.github.com/users/intacadmin/repos","events_url":"https://api.github.com/users/intacadmin/events{/privacy}","received_events_url":"https://api.github.com/users/intacadmin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2014-09-03T12:27:22Z","updated_at":"2015-11-27T22:01:17Z","closed_at":"2015-11-27T22:01:17Z","body":"I tried the master branch last night and and ran into a couple of issues.  One when using a collection representer and one when using a singular representer for each item in the collection.  The details are listed below.\r\n\r\nMy environment is:\r\n\r\n- Mac OSX Maverick\r\n- Ruby 2.0\r\n- roar master branch\r\n\r\nWhen I used:\r\n```\r\nroles = Roles.all\r\nrespond_with roles, :represent_with => RolesRepresenter\r\n```\r\n\r\nHere is my representer\r\n```\r\nrequire 'roar/json/json_api'\r\n\r\nmodule RolesRepresenter\r\n  include Roar::JSON::JsonApi\r\n\r\n  name :roles\r\n\r\n  property :name\r\n  # property :id\r\n  # property :description\r\n\r\nend\r\n```\r\n\r\nThe request only succeeds if I have name as a property.  It appears that the Class is being represented not the items.  I may be doing something wrong in the Representer.\r\n\r\nOr else I get an error like the following:\r\nNoMethodError at /api/v1/roles\r\n==============================\r\n\r\n> undefined method `id' for #<Role::ActiveRecord_Relation:0x007f89e758e378>\r\n\r\napp/controllers/api/v1/roles_controller.rb, line 7\r\n--------------------------------------------------\r\n\r\n``` ruby\r\n    2   class Api::V1::RolesController < Api::V1::BaseEntityController\r\n    3     include Roar::Rails::ControllerAdditions\r\n    4   \r\n    5     def index\r\n    6       roles = Role.all\r\n>   7       respond_with roles, :represent_with => RolesRepresenter\r\n    8     end\r\n    9   \r\n   10     private\r\n   11   \r\n   12     def _entity_params\r\n```\r\n\r\nApp backtrace\r\n-------------\r\n\r\n - app/controllers/api/v1/roles_controller.rb:7:in `index'\r\n\r\nFull backtrace\r\n--------------\r\n\r\n - activerecord (4.1.4) lib/active_record/relation/delegation.rb:136:in `method_missing'\r\n - activerecord (4.1.4) lib/active_record/relation/delegation.rb:99:in `method_missing'\r\n - representable (2.0.4) lib/representable/binding.rb:86:in `block in get'\r\n - representable (2.0.4) lib/representable/binding.rb:122:in `evaluate_option'\r\n - representable (2.0.4) lib/representable/binding.rb:85:in `get'\r\n - representable (2.0.4) lib/representable/binding.rb:34:in `block in compile_fragment'\r\n - representable (2.0.4) lib/representable/binding.rb:122:in `evaluate_option'\r\n - representable (2.0.4) lib/representable/binding.rb:33:in `compile_fragment'\r\n - representable (2.0.4) lib/representable/mapper.rb:64:in `compile_fragment'\r\n - representable (2.0.4) lib/representable/mapper.rb:30:in `serialize_property'\r\n - representable (2.0.4) lib/representable/mapper.rb:22:in `block in serialize'\r\n - representable (2.0.4) lib/representable/mapper.rb:21:in `serialize'\r\n - representable (2.0.4) lib/representable.rb:39:in `create_representation_with'\r\n - representable (2.0.4) lib/representable/hash.rb:35:in `to_hash'\r\n -  () Users/mcobery/.rvm/gems/ruby-2.0.0-p481/bundler/gems/roar-90e22ddb3591/lib/roar/json/json_api.rb:38:in `to_hash'\r\n -  () Users/mcobery/.rvm/gems/ruby-2.0.0-p481/bundler/gems/roar-90e22ddb3591/lib/roar/json/json_api.rb:110:in `to_hash'\r\n - representable (2.0.4) lib/representable/json.rb:35:in `to_json'\r\n - roar-rails (0.1.6) lib/roar/rails/responder.rb:36:in `create_response'\r\n - roar-rails (0.1.6) lib/roar/rails/responder.rb:11:in `display'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:208:in `api_behavior'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:186:in `rescue in to_format'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:180:in `to_format'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:158:in `respond'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:151:in `call'\r\n - actionpack (4.1.4) lib/action_controller/metal/mime_responds.rb:400:in `respond_with'\r\n - app/controllers/api/v1/roles_controller.rb:7:in `index'\r\n\r\nWhen I used:\r\n```\r\nroles = Roles.all\r\nrespond_with roles, :represent_items_with => RoleRepresenter\r\n```\r\n\r\nHere is my representer\r\n```\r\nrequire 'roar/json/json_api'\r\n\r\nmodule RoleRepresenter\r\n  include Roar::JSON::JsonApi\r\n\r\n  property :id\r\n  property :name\r\n  property :description\r\n  property :created_at\r\nend\r\n```\r\nI got the following error.\r\n> undefined method `map!' for #<Role::ActiveRecord_Relation:0x007f89e708a480>\r\n\r\napp/controllers/api/v1/roles_controller.rb, line 7\r\n--------------------------------------------------\r\n\r\n``` ruby\r\n    2   class Api::V1::RolesController < Api::V1::BaseEntityController\r\n    3     include Roar::Rails::ControllerAdditions\r\n    4   \r\n    5     def index\r\n    6       roles = Role.all\r\n>   7       respond_with roles, :represent_items_with => RoleRepresenter\r\n    8     end\r\n    9   \r\n   10     private\r\n   11   \r\n   12     def _entity_params\r\n```\r\n\r\nApp backtrace\r\n-------------\r\n\r\n - app/controllers/api/v1/roles_controller.rb:7:in `index'\r\n\r\nFull backtrace\r\n--------------\r\n\r\n - activerecord (4.1.4) lib/active_record/relation/delegation.rb:136:in `method_missing'\r\n - activerecord (4.1.4) lib/active_record/relation/delegation.rb:99:in `method_missing'\r\n - roar-rails (0.1.6) lib/roar/rails/responder.rb:47:in `setup_items_with'\r\n - roar-rails (0.1.6) lib/roar/rails/responder.rb:42:in `handle_lonely_collection!'\r\n - roar-rails (0.1.6) lib/roar/rails/responder.rb:6:in `display'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:208:in `api_behavior'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:186:in `rescue in to_format'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:180:in `to_format'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:158:in `respond'\r\n - actionpack (4.1.4) lib/action_controller/metal/responder.rb:151:in `call'\r\n - actionpack (4.1.4) lib/action_controller/metal/mime_responds.rb:400:in `respond_with'\r\n - app/controllers/api/v1/roles_controller.rb:7:in `index'"},"comment":{"url":"https://api.github.com/repos/apotonick/roar/issues/comments/160218255","html_url":"https://github.com/apotonick/roar/issues/104#issuecomment-160218255","issue_url":"https://api.github.com/repos/apotonick/roar/issues/104","id":160218255,"user":{"login":"apotonick","id":10406,"avatar_url":"https://avatars.githubusercontent.com/u/10406?v=3","gravatar_id":"","url":"https://api.github.com/users/apotonick","html_url":"https://github.com/apotonick","followers_url":"https://api.github.com/users/apotonick/followers","following_url":"https://api.github.com/users/apotonick/following{/other_user}","gists_url":"https://api.github.com/users/apotonick/gists{/gist_id}","starred_url":"https://api.github.com/users/apotonick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apotonick/subscriptions","organizations_url":"https://api.github.com/users/apotonick/orgs","repos_url":"https://api.github.com/users/apotonick/repos","events_url":"https://api.github.com/users/apotonick/events{/privacy}","received_events_url":"https://api.github.com/users/apotonick/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T22:01:17Z","updated_at":"2015-11-27T22:01:17Z","body":"Fixed in master."}}