{"action":"created","comment":{"url":"https://api.github.com/repos/tomohung/myflix/pulls/comments/26228900","id":26228900,"diff_hunk":"@@ -0,0 +1,36 @@\n+class QueueItemsController < ApplicationController\n+\n+  before_filter :require_logged_in\n+\n+  def index\n+    if logged_in?\n+      @queue_items = current_user.queue_items\n+    else\n+      redirect_to sign_in_path\n+    end\n+  end\n+\n+  def create\n+\n+    video = Video.find(params[:video_id])\n+    if video && !current_user_queue_include?(video)\n+      queue_item = QueueItem.new(user: current_user, video: video)\n+      queue_item.position = current_user.queue_items.count + 1\n+      queue_item.save\n+    end\n+    redirect_to my_queue_path\n+  end\n+\n+  def destroy\n+    queue_item = QueueItem.find(params[:id])\n+    queue_item.destroy if queue_item.user == current_user\n+    redirect_to my_queue_path\n+  end\n+\n+private\n+\n+  def current_user_queue_include?(video)","path":"app/controllers/queue_items_controller.rb","position":32,"original_position":32,"commit_id":"8dd9f9ac782c0b524f4d3950176b8414e000c491","original_commit_id":"53074edcac16f9765b51bac2a19835b2285ca531","user":{"login":"brandoncc","id":543973,"avatar_url":"https://avatars.githubusercontent.com/u/543973?v=3","gravatar_id":"","url":"https://api.github.com/users/brandoncc","html_url":"https://github.com/brandoncc","followers_url":"https://api.github.com/users/brandoncc/followers","following_url":"https://api.github.com/users/brandoncc/following{/other_user}","gists_url":"https://api.github.com/users/brandoncc/gists{/gist_id}","starred_url":"https://api.github.com/users/brandoncc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandoncc/subscriptions","organizations_url":"https://api.github.com/users/brandoncc/orgs","repos_url":"https://api.github.com/users/brandoncc/repos","events_url":"https://api.github.com/users/brandoncc/events{/privacy}","received_events_url":"https://api.github.com/users/brandoncc/received_events","type":"User","site_admin":false},"body":"Actually, I think you do know how to do it. I just mean that you can create a method in your `User` model which provides this functionality. Like this:\r\n\r\n```ruby\r\nclass User < ActiveRecord::Base\r\n  def queue_includes?(video)\r\n    queue_items.map(&:video).include?(video)\r\n  end\r\nend\r\n```\r\n\r\nThen you can use it here like this:\r\n\r\n```ruby\r\ncurrent_user.queue_includes?(video)\r\n```\r\n\r\nA major advantage to this is that you would then have access to that method from everywhere in your app.","created_at":"2015-03-11T16:32:08Z","updated_at":"2015-03-11T16:32:08Z","html_url":"https://github.com/tomohung/myflix/pull/6#discussion_r26228900","pull_request_url":"https://api.github.com/repos/tomohung/myflix/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/comments/26228900"},"html":{"href":"https://github.com/tomohung/myflix/pull/6#discussion_r26228900"},"pull_request":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/tomohung/myflix/pulls/6","id":30912431,"html_url":"https://github.com/tomohung/myflix/pull/6","diff_url":"https://github.com/tomohung/myflix/pull/6.diff","patch_url":"https://github.com/tomohung/myflix/pull/6.patch","issue_url":"https://api.github.com/repos/tomohung/myflix/issues/6","number":6,"state":"open","locked":false,"title":"Video queue","user":{"login":"tomohung","id":3352926,"avatar_url":"https://avatars.githubusercontent.com/u/3352926?v=3","gravatar_id":"","url":"https://api.github.com/users/tomohung","html_url":"https://github.com/tomohung","followers_url":"https://api.github.com/users/tomohung/followers","following_url":"https://api.github.com/users/tomohung/following{/other_user}","gists_url":"https://api.github.com/users/tomohung/gists{/gist_id}","starred_url":"https://api.github.com/users/tomohung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomohung/subscriptions","organizations_url":"https://api.github.com/users/tomohung/orgs","repos_url":"https://api.github.com/users/tomohung/repos","events_url":"https://api.github.com/users/tomohung/events{/privacy}","received_events_url":"https://api.github.com/users/tomohung/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-11T03:09:39Z","updated_at":"2015-03-11T16:32:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"accf81eb233028de02adbe49181424a8d0285cdd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tomohung/myflix/pulls/6/commits","review_comments_url":"https://api.github.com/repos/tomohung/myflix/pulls/6/comments","review_comment_url":"https://api.github.com/repos/tomohung/myflix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tomohung/myflix/issues/6/comments","statuses_url":"https://api.github.com/repos/tomohung/myflix/statuses/8dd9f9ac782c0b524f4d3950176b8414e000c491","head":{"label":"tomohung:video_queue","ref":"video_queue","sha":"8dd9f9ac782c0b524f4d3950176b8414e000c491","user":{"login":"tomohung","id":3352926,"avatar_url":"https://avatars.githubusercontent.com/u/3352926?v=3","gravatar_id":"","url":"https://api.github.com/users/tomohung","html_url":"https://github.com/tomohung","followers_url":"https://api.github.com/users/tomohung/followers","following_url":"https://api.github.com/users/tomohung/following{/other_user}","gists_url":"https://api.github.com/users/tomohung/gists{/gist_id}","starred_url":"https://api.github.com/users/tomohung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomohung/subscriptions","organizations_url":"https://api.github.com/users/tomohung/orgs","repos_url":"https://api.github.com/users/tomohung/repos","events_url":"https://api.github.com/users/tomohung/events{/privacy}","received_events_url":"https://api.github.com/users/tomohung/received_events","type":"User","site_admin":false},"repo":{"id":31462876,"name":"myflix","full_name":"tomohung/myflix","owner":{"login":"tomohung","id":3352926,"avatar_url":"https://avatars.githubusercontent.com/u/3352926?v=3","gravatar_id":"","url":"https://api.github.com/users/tomohung","html_url":"https://github.com/tomohung","followers_url":"https://api.github.com/users/tomohung/followers","following_url":"https://api.github.com/users/tomohung/following{/other_user}","gists_url":"https://api.github.com/users/tomohung/gists{/gist_id}","starred_url":"https://api.github.com/users/tomohung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomohung/subscriptions","organizations_url":"https://api.github.com/users/tomohung/orgs","repos_url":"https://api.github.com/users/tomohung/repos","events_url":"https://api.github.com/users/tomohung/events{/privacy}","received_events_url":"https://api.github.com/users/tomohung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tomohung/myflix","description":"","fork":false,"url":"https://api.github.com/repos/tomohung/myflix","forks_url":"https://api.github.com/repos/tomohung/myflix/forks","keys_url":"https://api.github.com/repos/tomohung/myflix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomohung/myflix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomohung/myflix/teams","hooks_url":"https://api.github.com/repos/tomohung/myflix/hooks","issue_events_url":"https://api.github.com/repos/tomohung/myflix/issues/events{/number}","events_url":"https://api.github.com/repos/tomohung/myflix/events","assignees_url":"https://api.github.com/repos/tomohung/myflix/assignees{/user}","branches_url":"https://api.github.com/repos/tomohung/myflix/branches{/branch}","tags_url":"https://api.github.com/repos/tomohung/myflix/tags","blobs_url":"https://api.github.com/repos/tomohung/myflix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomohung/myflix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomohung/myflix/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomohung/myflix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomohung/myflix/statuses/{sha}","languages_url":"https://api.github.com/repos/tomohung/myflix/languages","stargazers_url":"https://api.github.com/repos/tomohung/myflix/stargazers","contributors_url":"https://api.github.com/repos/tomohung/myflix/contributors","subscribers_url":"https://api.github.com/repos/tomohung/myflix/subscribers","subscription_url":"https://api.github.com/repos/tomohung/myflix/subscription","commits_url":"https://api.github.com/repos/tomohung/myflix/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomohung/myflix/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomohung/myflix/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomohung/myflix/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomohung/myflix/contents/{+path}","compare_url":"https://api.github.com/repos/tomohung/myflix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomohung/myflix/merges","archive_url":"https://api.github.com/repos/tomohung/myflix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomohung/myflix/downloads","issues_url":"https://api.github.com/repos/tomohung/myflix/issues{/number}","pulls_url":"https://api.github.com/repos/tomohung/myflix/pulls{/number}","milestones_url":"https://api.github.com/repos/tomohung/myflix/milestones{/number}","notifications_url":"https://api.github.com/repos/tomohung/myflix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomohung/myflix/labels{/name}","releases_url":"https://api.github.com/repos/tomohung/myflix/releases{/id}","created_at":"2015-02-28T13:06:58Z","updated_at":"2015-03-09T22:29:09Z","pushed_at":"2015-03-11T06:23:06Z","git_url":"git://github.com/tomohung/myflix.git","ssh_url":"git@github.com:tomohung/myflix.git","clone_url":"https://github.com/tomohung/myflix.git","svn_url":"https://github.com/tomohung/myflix","homepage":null,"size":392,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"tomohung:master","ref":"master","sha":"e641ddf67798bd486fd51bd25030b44ce2e572ec","user":{"login":"tomohung","id":3352926,"avatar_url":"https://avatars.githubusercontent.com/u/3352926?v=3","gravatar_id":"","url":"https://api.github.com/users/tomohung","html_url":"https://github.com/tomohung","followers_url":"https://api.github.com/users/tomohung/followers","following_url":"https://api.github.com/users/tomohung/following{/other_user}","gists_url":"https://api.github.com/users/tomohung/gists{/gist_id}","starred_url":"https://api.github.com/users/tomohung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomohung/subscriptions","organizations_url":"https://api.github.com/users/tomohung/orgs","repos_url":"https://api.github.com/users/tomohung/repos","events_url":"https://api.github.com/users/tomohung/events{/privacy}","received_events_url":"https://api.github.com/users/tomohung/received_events","type":"User","site_admin":false},"repo":{"id":31462876,"name":"myflix","full_name":"tomohung/myflix","owner":{"login":"tomohung","id":3352926,"avatar_url":"https://avatars.githubusercontent.com/u/3352926?v=3","gravatar_id":"","url":"https://api.github.com/users/tomohung","html_url":"https://github.com/tomohung","followers_url":"https://api.github.com/users/tomohung/followers","following_url":"https://api.github.com/users/tomohung/following{/other_user}","gists_url":"https://api.github.com/users/tomohung/gists{/gist_id}","starred_url":"https://api.github.com/users/tomohung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomohung/subscriptions","organizations_url":"https://api.github.com/users/tomohung/orgs","repos_url":"https://api.github.com/users/tomohung/repos","events_url":"https://api.github.com/users/tomohung/events{/privacy}","received_events_url":"https://api.github.com/users/tomohung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tomohung/myflix","description":"","fork":false,"url":"https://api.github.com/repos/tomohung/myflix","forks_url":"https://api.github.com/repos/tomohung/myflix/forks","keys_url":"https://api.github.com/repos/tomohung/myflix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomohung/myflix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomohung/myflix/teams","hooks_url":"https://api.github.com/repos/tomohung/myflix/hooks","issue_events_url":"https://api.github.com/repos/tomohung/myflix/issues/events{/number}","events_url":"https://api.github.com/repos/tomohung/myflix/events","assignees_url":"https://api.github.com/repos/tomohung/myflix/assignees{/user}","branches_url":"https://api.github.com/repos/tomohung/myflix/branches{/branch}","tags_url":"https://api.github.com/repos/tomohung/myflix/tags","blobs_url":"https://api.github.com/repos/tomohung/myflix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomohung/myflix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomohung/myflix/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomohung/myflix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomohung/myflix/statuses/{sha}","languages_url":"https://api.github.com/repos/tomohung/myflix/languages","stargazers_url":"https://api.github.com/repos/tomohung/myflix/stargazers","contributors_url":"https://api.github.com/repos/tomohung/myflix/contributors","subscribers_url":"https://api.github.com/repos/tomohung/myflix/subscribers","subscription_url":"https://api.github.com/repos/tomohung/myflix/subscription","commits_url":"https://api.github.com/repos/tomohung/myflix/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomohung/myflix/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomohung/myflix/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomohung/myflix/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomohung/myflix/contents/{+path}","compare_url":"https://api.github.com/repos/tomohung/myflix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomohung/myflix/merges","archive_url":"https://api.github.com/repos/tomohung/myflix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomohung/myflix/downloads","issues_url":"https://api.github.com/repos/tomohung/myflix/issues{/number}","pulls_url":"https://api.github.com/repos/tomohung/myflix/pulls{/number}","milestones_url":"https://api.github.com/repos/tomohung/myflix/milestones{/number}","notifications_url":"https://api.github.com/repos/tomohung/myflix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomohung/myflix/labels{/name}","releases_url":"https://api.github.com/repos/tomohung/myflix/releases{/id}","created_at":"2015-02-28T13:06:58Z","updated_at":"2015-03-09T22:29:09Z","pushed_at":"2015-03-11T06:23:06Z","git_url":"git://github.com/tomohung/myflix.git","ssh_url":"git@github.com:tomohung/myflix.git","clone_url":"https://github.com/tomohung/myflix.git","svn_url":"https://github.com/tomohung/myflix","homepage":null,"size":392,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/6"},"html":{"href":"https://github.com/tomohung/myflix/pull/6"},"issue":{"href":"https://api.github.com/repos/tomohung/myflix/issues/6"},"comments":{"href":"https://api.github.com/repos/tomohung/myflix/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tomohung/myflix/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/tomohung/myflix/statuses/8dd9f9ac782c0b524f4d3950176b8414e000c491"}}}}