{"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/48694155","id":48694155,"diff_hunk":"@@ -65,19 +98,49 @@ def use_renderers(*args)\n         self._renderers = renderers.freeze\n       end\n       alias use_renderer use_renderers\n+\n+      # See <tt>Renderers.use_renderers</tt>\n+      def use_serializers(*args)\n+        serializers = _serializers + args\n+        self._serializers = serializers.freeze\n+      end\n+      alias use_serializer use_serializers\n+    end\n+\n+    def has_serializer?(key)\n+      _serializers.key?(key)\n     end\n \n+    def serializer_for(key)\n+      _serializers[key]\n+    end\n+\n+    def assert_serializer!(serializer_name)\n+      return true if has_serializer?(serializer_name)\n+      raise ActionController::MissingSerializer, \"There is no '#{serializer_name}' serializer.\\n\" <<\n+            \"Known serializers are #{_serializers.keys}\"\n+    end","path":"actionpack/lib/action_controller/metal/renderers.rb","position":72,"original_position":72,"commit_id":"3882b2a95ed0e166c1143e815670face2a498778","original_commit_id":"3882b2a95ed0e166c1143e815670face2a498778","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"body":"Only that it makes the `_render_to_body_with_renderer` method a little more manageable\r\n\r\n```diff\r\n    def _render_to_body_with_renderer(options)\r\n      _renderers.each do |name|\r\n-        if options.key?(name)\r\n-          _process_options(options)\r\n-          method_name = Renderers._render_with_renderer_method_name(name)\r\n-          return send(method_name, options.delete(name), options)\r\n-        end\r\n+        next unless options.key?(name)\r\n+        _process_options(options)\r\n+        method_name = Renderers._render_with_renderer_method_name(name)\r\n+        value = options.delete(name)\r\n+        serializer_name = options.key?(:serializer_name) ? options.delete(:serializer_name) : name\r\n+        assert_serializer!(serializer_name)\r\n+        serializer = serializer_for(serializer_name)\r\n+        value = serializer.call(value, options)\r\n+        return send(method_name, value, options)\r\n      end\r\n      nil\r\n    end\r\n```\r\n","created_at":"2016-01-03T15:40:53Z","updated_at":"2016-01-03T15:40:53Z","html_url":"https://github.com/rails/rails/pull/21496#discussion_r48694155","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/21496","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/48694155"},"html":{"href":"https://github.com/rails/rails/pull/21496#discussion_r48694155"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/21496"}}},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/21496","id":44201804,"html_url":"https://github.com/rails/rails/pull/21496","diff_url":"https://github.com/rails/rails/pull/21496.diff","patch_url":"https://github.com/rails/rails/pull/21496.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/21496","number":21496,"state":"open","locked":false,"title":"Add configurable serializers in each renderer","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"body":"per https://groups.google.com/forum/#!topic/rubyonrails-core/K8t4-DZ_DkQ/discussion\r\n\r\n- [x] Separate serializer definition from renderer\r\n- [x] Allow specifying `serializer_name` via params\r\n- [x] Changelog\r\n- [ ] Guides \r\n  - [ ] [guides/source/api_app.md](https://github.com/rails/rails/pull/19832/files#diff-70cc8da393475ab7f80a5625887b0dc9R1)\r\n  - [ ] https://github.com/rails/rails/blob/master/guides/source/layouts_and_rendering.md\r\n- [ ] clean up tests, perhaps into different files and possibly separate into unit and controller tests\r\n- [ ] Agree on implementation\r\n- [ ] raise ActionController::MissingRenderer instead of ActionView::MissingTemplate\r\n- [ ] consider which new public methods to introduce\r\n- [ ] consider effects on the [responders lib](https://github.com/plataformatec/responders)\r\n- [ ] more tests?\r\n\r\nSome background on the relationship between active_model_serializers ([now included in the default Rails Gemfile](https://github.com/rails/rails/pull/19832/files#diff-70cc8da393475ab7f80a5625887b0dc9R1)) and serialization in Rails.\r\n\r\n- [Creation of `ActiveModel::Serializers::JSON` in Rails (2009)](https://github.com/rails/rails/commit/fbdf706fffbfb17731a1f459203d242414ef5086)\r\n- [Creation of `ActiveModel::Serializer` in Rails (2009)](https://github.com/rails/rails/commit/d2b78b3594b9cc9870e6a6ebfeb2e56d00e6ddb8#diff-80d5beeced9bdc24ca2b04a201543bdd)\r\n- [Integration of `ActiveModel::Serializer` into `ActiveRecord::Serialization`](https://github.com/rails/rails/commit/783db25e0c640c1588732967a87d65c10fddc08e)\r\n- [Creation of `ActiveModel::Serialization` from `ActiveModel::Serializer` in Rails (2009)](https://github.com/rails/rails/commit/c6bc8e662614be711f45a8d4b231d5f993b024a7#diff-d029b9768d8df0407a35804a468e3ae5)\r\n- [Proposed Implementation to Rails 3.2 by @wycats and @josevalim (November 25, 2011)](https://github.com/rails/rails/pull/3753)\r\n  - [Docs and CHANGELOG](https://github.com/rails/rails/commit/696d01f7f4a8ed787924a41cce6df836cd73c46f)\r\n  - [Deprecation of ActiveModel::Serialization to ActiveModel::Serializable](https://github.com/rails/rails/blob/696d01f7f4a8ed787924a41cce6df836cd73c46f/activemodel/lib/active_model/serialization.rb)\r\n- [Changing Serialization/Serializers namespace to `Serializable` (November 30, 2011)](https://github.com/rails/rails/commit/8896b4fdc8a543157cdf4dfc378607ebf6c10ab0)\r\n  - \"[Merge branch 'serializers'. This implements the ActiveModel::Serializer object. Includes code, tests, generators and guides. From José and Yehuda with love.]\"(https://github.com/rails/rails/commit/fcacc6986ab60f1fb2e423a73bf47c7abd7b191d)\r\n  - But [was reverted](https://github.com/rails/rails/commit/5b2eb64ceb08cd005dc06b721935de5853971473).\r\n    \"[Revert the serializers API as other alternatives are now also under discussion](https://github.com/rails/rails/commit/0a4035b12a6c59253cb60f9e3456513c6a6a9d33)\".\r\n- First Commit of ActiveModelSerializers as [Rails Serializers 0.0.1](https://github.com/rails-api/active_model_serializers/commit/d72b66d4c5355b0ff0a75a04895fcc4ea5b0c65e)\r\n  (December 1, 2011).\r\n- Now, Rails has [ActiveModel::Serializers::JSON](https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serializers/json.rb) and [ActiveModel::Serialization](https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serialization.rb). \r\n  - [ActiveModel::Serializers::Xml](https://github.com/rails/rails/commit/f7ebdb1ac51f26cff76e5642a75717df1b446746) was recently removed from Rails.\r\n  - (Recently [the ActiveModelSerializers team started thinking about what the name of the gem should be](https://github.com/rails-api/active_model_serializers/pull/1259#discussion_r42073706).\r\n\r\nSince 2011, work in EmberJS and on the JSON API has resulted in some changing naming conventions\r\n\r\n- Model:  class that defines the properties and behavior of the data that you present to the user.\r\n- Record: A record is an instance of a model that contains data loaded from a server. Your application can also create new records and save them back to the server.\r\n- Adapter: knows how to talk to your server. knows how to translate requests from the client into requests on your server. object that translates requests from AMS/Rails/Grape etc (such as \"find the user with an ID of 123\") into a requests to a server. let you completely change how your API is implemented without impacting your application code.\r\n- Serializer: maps keys and values to desired format, see https://github.com/orbitjs/orbit.js/blob/master/lib/orbit-common/jsonapi-serializer.js\r\n- Store: the central repository of records in your application, use the store to retrieve records, as well to create new ones. The store will automatically cache records for you.\r\n","created_at":"2015-09-04T10:08:54Z","updated_at":"2016-01-03T15:40:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fd347d75667e946501d250f3997ecfc3b78d81fe","assignee":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/21496/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/21496/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/21496/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/3882b2a95ed0e166c1143e815670face2a498778","head":{"label":"bf4:serializer_for_renderer","ref":"serializer_for_renderer","sha":"3882b2a95ed0e166c1143e815670face2a498778","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"repo":{"id":10260023,"name":"rails","full_name":"bf4/rails","owner":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bf4/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/bf4/rails","forks_url":"https://api.github.com/repos/bf4/rails/forks","keys_url":"https://api.github.com/repos/bf4/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bf4/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bf4/rails/teams","hooks_url":"https://api.github.com/repos/bf4/rails/hooks","issue_events_url":"https://api.github.com/repos/bf4/rails/issues/events{/number}","events_url":"https://api.github.com/repos/bf4/rails/events","assignees_url":"https://api.github.com/repos/bf4/rails/assignees{/user}","branches_url":"https://api.github.com/repos/bf4/rails/branches{/branch}","tags_url":"https://api.github.com/repos/bf4/rails/tags","blobs_url":"https://api.github.com/repos/bf4/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bf4/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bf4/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/bf4/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bf4/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/bf4/rails/languages","stargazers_url":"https://api.github.com/repos/bf4/rails/stargazers","contributors_url":"https://api.github.com/repos/bf4/rails/contributors","subscribers_url":"https://api.github.com/repos/bf4/rails/subscribers","subscription_url":"https://api.github.com/repos/bf4/rails/subscription","commits_url":"https://api.github.com/repos/bf4/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/bf4/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/bf4/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/bf4/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/bf4/rails/contents/{+path}","compare_url":"https://api.github.com/repos/bf4/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bf4/rails/merges","archive_url":"https://api.github.com/repos/bf4/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bf4/rails/downloads","issues_url":"https://api.github.com/repos/bf4/rails/issues{/number}","pulls_url":"https://api.github.com/repos/bf4/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/bf4/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/bf4/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bf4/rails/labels{/name}","releases_url":"https://api.github.com/repos/bf4/rails/releases{/id}","created_at":"2013-05-24T05:39:41Z","updated_at":"2014-08-18T02:52:28Z","pushed_at":"2016-01-01T01:56:50Z","git_url":"git://github.com/bf4/rails.git","ssh_url":"git@github.com:bf4/rails.git","clone_url":"https://github.com/bf4/rails.git","svn_url":"https://github.com/bf4/rails","homepage":"http://rubyonrails.org","size":117400,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"e991c7b8cd69d7ba5e221a19e5f386e3ba02eb9d","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2016-01-03T14:11:05Z","pushed_at":"2016-01-03T15:25:11Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":320430,"stargazers_count":28992,"watchers_count":28992,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11735,"mirror_url":null,"open_issues_count":859,"forks":11735,"open_issues":859,"watchers":28992,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/21496"},"html":{"href":"https://github.com/rails/rails/pull/21496"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/21496"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/21496/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/21496/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/21496/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/3882b2a95ed0e166c1143e815670face2a498778"}}}}