{"action":"created","comment":{"url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/comments/27910240","id":27910240,"diff_hunk":"@@ -0,0 +1,29 @@\n+class DownvotesController < ApplicationController\n+  before_action :authenticate_user!\n+\n+  def create","path":"app/controllers/downvotes_controller.rb","position":4,"original_position":4,"commit_id":"d3a19ffa2bce51509d901d8fa679cf5fb2aed1ce","original_commit_id":"d3a19ffa2bce51509d901d8fa679cf5fb2aed1ce","user":{"login":"dreamingfurther","id":1883346,"avatar_url":"https://avatars.githubusercontent.com/u/1883346?v=3","gravatar_id":"","url":"https://api.github.com/users/dreamingfurther","html_url":"https://github.com/dreamingfurther","followers_url":"https://api.github.com/users/dreamingfurther/followers","following_url":"https://api.github.com/users/dreamingfurther/following{/other_user}","gists_url":"https://api.github.com/users/dreamingfurther/gists{/gist_id}","starred_url":"https://api.github.com/users/dreamingfurther/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dreamingfurther/subscriptions","organizations_url":"https://api.github.com/users/dreamingfurther/orgs","repos_url":"https://api.github.com/users/dreamingfurther/repos","events_url":"https://api.github.com/users/dreamingfurther/events{/privacy}","received_events_url":"https://api.github.com/users/dreamingfurther/received_events","type":"User","site_admin":false},"body":"Basically everything in this controller is a perfect candidate for a refactor into a PORO (plain old ruby object). Everything that this controller is doing can basically be boiled down into handling the logic of 'making a downvote'.\r\n\r\nHere is an example of how I would recommend refactoring this controller. (You'll need to figure out how to write the code to make this work.)\r\n\r\n```\r\ndef create\r\n    VoteManager.new(current_user, review).downvote\r\n    redirect_to sitcom\r\nend\r\n```\r\n\r\nYour VoteManager object would get initialized with the user and the review object and then have the `downvote` method called on it. I'm suggesting a `VoteManager` object because for your UpvotesController you'd probably want to have a `upvote` method to call on that object since I'd guess that they both share some of the same concerns or logic.\r\n\r\nI suggest initializing it with the user and review because you are then passing it all the data (user and review) and information about what you want done with that date (calling the method downvote). You'd probably start your `VoteManager` class like so:\r\n\r\n````\r\nclass VoteManager\r\n    attr_reader :user, :review\r\n\r\n    def initialize(user, review)\r\n        @user = user\r\n        @review = review\r\n    end\r\n\r\n    def downvote\r\n        ...<your code>\r\n    end\r\nend\r\n","created_at":"2015-04-07T19:15:02Z","updated_at":"2015-04-07T19:15:02Z","html_url":"https://github.com/Tobitron/sitcom-review/pull/11#discussion_r27910240","pull_request_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/comments/27910240"},"html":{"href":"https://github.com/Tobitron/sitcom-review/pull/11#discussion_r27910240"},"pull_request":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11","id":32786370,"html_url":"https://github.com/Tobitron/sitcom-review/pull/11","diff_url":"https://github.com/Tobitron/sitcom-review/pull/11.diff","patch_url":"https://github.com/Tobitron/sitcom-review/pull/11.patch","issue_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/11","number":11,"state":"closed","locked":false,"title":"RFR: Tk review voting","user":{"login":"RoccStar","id":9888578,"avatar_url":"https://avatars.githubusercontent.com/u/9888578?v=3","gravatar_id":"","url":"https://api.github.com/users/RoccStar","html_url":"https://github.com/RoccStar","followers_url":"https://api.github.com/users/RoccStar/followers","following_url":"https://api.github.com/users/RoccStar/following{/other_user}","gists_url":"https://api.github.com/users/RoccStar/gists{/gist_id}","starred_url":"https://api.github.com/users/RoccStar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoccStar/subscriptions","organizations_url":"https://api.github.com/users/RoccStar/orgs","repos_url":"https://api.github.com/users/RoccStar/repos","events_url":"https://api.github.com/users/RoccStar/events{/privacy}","received_events_url":"https://api.github.com/users/RoccStar/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-07T17:29:32Z","updated_at":"2015-04-07T19:15:02Z","closed_at":"2015-04-07T18:37:08Z","merged_at":"2015-04-07T18:37:08Z","merge_commit_sha":"483406c006116d1211f91c0b532bb1e647032e2f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11/commits","review_comments_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11/comments","review_comment_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/11/comments","statuses_url":"https://api.github.com/repos/Tobitron/sitcom-review/statuses/d3a19ffa2bce51509d901d8fa679cf5fb2aed1ce","head":{"label":"Tobitron:TK-review-voting","ref":"TK-review-voting","sha":"d3a19ffa2bce51509d901d8fa679cf5fb2aed1ce","user":{"login":"Tobitron","id":2693541,"avatar_url":"https://avatars.githubusercontent.com/u/2693541?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobitron","html_url":"https://github.com/Tobitron","followers_url":"https://api.github.com/users/Tobitron/followers","following_url":"https://api.github.com/users/Tobitron/following{/other_user}","gists_url":"https://api.github.com/users/Tobitron/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobitron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobitron/subscriptions","organizations_url":"https://api.github.com/users/Tobitron/orgs","repos_url":"https://api.github.com/users/Tobitron/repos","events_url":"https://api.github.com/users/Tobitron/events{/privacy}","received_events_url":"https://api.github.com/users/Tobitron/received_events","type":"User","site_admin":false},"repo":{"id":33130275,"name":"sitcom-review","full_name":"Tobitron/sitcom-review","owner":{"login":"Tobitron","id":2693541,"avatar_url":"https://avatars.githubusercontent.com/u/2693541?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobitron","html_url":"https://github.com/Tobitron","followers_url":"https://api.github.com/users/Tobitron/followers","following_url":"https://api.github.com/users/Tobitron/following{/other_user}","gists_url":"https://api.github.com/users/Tobitron/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobitron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobitron/subscriptions","organizations_url":"https://api.github.com/users/Tobitron/orgs","repos_url":"https://api.github.com/users/Tobitron/repos","events_url":"https://api.github.com/users/Tobitron/events{/privacy}","received_events_url":"https://api.github.com/users/Tobitron/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Tobitron/sitcom-review","description":"A sitcom and comedy tv show review site.","fork":false,"url":"https://api.github.com/repos/Tobitron/sitcom-review","forks_url":"https://api.github.com/repos/Tobitron/sitcom-review/forks","keys_url":"https://api.github.com/repos/Tobitron/sitcom-review/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tobitron/sitcom-review/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tobitron/sitcom-review/teams","hooks_url":"https://api.github.com/repos/Tobitron/sitcom-review/hooks","issue_events_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/events{/number}","events_url":"https://api.github.com/repos/Tobitron/sitcom-review/events","assignees_url":"https://api.github.com/repos/Tobitron/sitcom-review/assignees{/user}","branches_url":"https://api.github.com/repos/Tobitron/sitcom-review/branches{/branch}","tags_url":"https://api.github.com/repos/Tobitron/sitcom-review/tags","blobs_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tobitron/sitcom-review/statuses/{sha}","languages_url":"https://api.github.com/repos/Tobitron/sitcom-review/languages","stargazers_url":"https://api.github.com/repos/Tobitron/sitcom-review/stargazers","contributors_url":"https://api.github.com/repos/Tobitron/sitcom-review/contributors","subscribers_url":"https://api.github.com/repos/Tobitron/sitcom-review/subscribers","subscription_url":"https://api.github.com/repos/Tobitron/sitcom-review/subscription","commits_url":"https://api.github.com/repos/Tobitron/sitcom-review/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tobitron/sitcom-review/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tobitron/sitcom-review/contents/{+path}","compare_url":"https://api.github.com/repos/Tobitron/sitcom-review/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tobitron/sitcom-review/merges","archive_url":"https://api.github.com/repos/Tobitron/sitcom-review/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tobitron/sitcom-review/downloads","issues_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues{/number}","pulls_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls{/number}","milestones_url":"https://api.github.com/repos/Tobitron/sitcom-review/milestones{/number}","notifications_url":"https://api.github.com/repos/Tobitron/sitcom-review/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tobitron/sitcom-review/labels{/name}","releases_url":"https://api.github.com/repos/Tobitron/sitcom-review/releases{/id}","created_at":"2015-03-30T15:07:51Z","updated_at":"2015-04-07T18:37:09Z","pushed_at":"2015-04-07T18:37:08Z","git_url":"git://github.com/Tobitron/sitcom-review.git","ssh_url":"git@github.com:Tobitron/sitcom-review.git","clone_url":"https://github.com/Tobitron/sitcom-review.git","svn_url":"https://github.com/Tobitron/sitcom-review","homepage":null,"size":360,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"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":"Tobitron:master","ref":"master","sha":"23f2a9c7cecba24911773209496df75e6cfdd7b1","user":{"login":"Tobitron","id":2693541,"avatar_url":"https://avatars.githubusercontent.com/u/2693541?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobitron","html_url":"https://github.com/Tobitron","followers_url":"https://api.github.com/users/Tobitron/followers","following_url":"https://api.github.com/users/Tobitron/following{/other_user}","gists_url":"https://api.github.com/users/Tobitron/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobitron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobitron/subscriptions","organizations_url":"https://api.github.com/users/Tobitron/orgs","repos_url":"https://api.github.com/users/Tobitron/repos","events_url":"https://api.github.com/users/Tobitron/events{/privacy}","received_events_url":"https://api.github.com/users/Tobitron/received_events","type":"User","site_admin":false},"repo":{"id":33130275,"name":"sitcom-review","full_name":"Tobitron/sitcom-review","owner":{"login":"Tobitron","id":2693541,"avatar_url":"https://avatars.githubusercontent.com/u/2693541?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobitron","html_url":"https://github.com/Tobitron","followers_url":"https://api.github.com/users/Tobitron/followers","following_url":"https://api.github.com/users/Tobitron/following{/other_user}","gists_url":"https://api.github.com/users/Tobitron/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobitron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobitron/subscriptions","organizations_url":"https://api.github.com/users/Tobitron/orgs","repos_url":"https://api.github.com/users/Tobitron/repos","events_url":"https://api.github.com/users/Tobitron/events{/privacy}","received_events_url":"https://api.github.com/users/Tobitron/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Tobitron/sitcom-review","description":"A sitcom and comedy tv show review site.","fork":false,"url":"https://api.github.com/repos/Tobitron/sitcom-review","forks_url":"https://api.github.com/repos/Tobitron/sitcom-review/forks","keys_url":"https://api.github.com/repos/Tobitron/sitcom-review/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tobitron/sitcom-review/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tobitron/sitcom-review/teams","hooks_url":"https://api.github.com/repos/Tobitron/sitcom-review/hooks","issue_events_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/events{/number}","events_url":"https://api.github.com/repos/Tobitron/sitcom-review/events","assignees_url":"https://api.github.com/repos/Tobitron/sitcom-review/assignees{/user}","branches_url":"https://api.github.com/repos/Tobitron/sitcom-review/branches{/branch}","tags_url":"https://api.github.com/repos/Tobitron/sitcom-review/tags","blobs_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tobitron/sitcom-review/statuses/{sha}","languages_url":"https://api.github.com/repos/Tobitron/sitcom-review/languages","stargazers_url":"https://api.github.com/repos/Tobitron/sitcom-review/stargazers","contributors_url":"https://api.github.com/repos/Tobitron/sitcom-review/contributors","subscribers_url":"https://api.github.com/repos/Tobitron/sitcom-review/subscribers","subscription_url":"https://api.github.com/repos/Tobitron/sitcom-review/subscription","commits_url":"https://api.github.com/repos/Tobitron/sitcom-review/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tobitron/sitcom-review/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tobitron/sitcom-review/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tobitron/sitcom-review/contents/{+path}","compare_url":"https://api.github.com/repos/Tobitron/sitcom-review/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tobitron/sitcom-review/merges","archive_url":"https://api.github.com/repos/Tobitron/sitcom-review/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tobitron/sitcom-review/downloads","issues_url":"https://api.github.com/repos/Tobitron/sitcom-review/issues{/number}","pulls_url":"https://api.github.com/repos/Tobitron/sitcom-review/pulls{/number}","milestones_url":"https://api.github.com/repos/Tobitron/sitcom-review/milestones{/number}","notifications_url":"https://api.github.com/repos/Tobitron/sitcom-review/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tobitron/sitcom-review/labels{/name}","releases_url":"https://api.github.com/repos/Tobitron/sitcom-review/releases{/id}","created_at":"2015-03-30T15:07:51Z","updated_at":"2015-04-07T18:37:09Z","pushed_at":"2015-04-07T18:37:08Z","git_url":"git://github.com/Tobitron/sitcom-review.git","ssh_url":"git@github.com:Tobitron/sitcom-review.git","clone_url":"https://github.com/Tobitron/sitcom-review.git","svn_url":"https://github.com/Tobitron/sitcom-review","homepage":null,"size":360,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11"},"html":{"href":"https://github.com/Tobitron/sitcom-review/pull/11"},"issue":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/issues/11"},"comments":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/Tobitron/sitcom-review/statuses/d3a19ffa2bce51509d901d8fa679cf5fb2aed1ce"}}}}