{"action":"created","comment":{"url":"https://api.github.com/repos/framgia/tms_8/pulls/comments/26196225","id":26196225,"diff_hunk":"@@ -1,4 +1,28 @@\n class UserCourse < ActiveRecord::Base\n   belongs_to :course\n   belongs_to :user\n+\n+  after_save :add_user_subject\n+  before_save :add_status\n+  before_destroy :delete_user_subject\n+\n+  scope :course_of_user,->(user_course) {where(course_id: user_course.course_id)}\n+\n+  private\n+  def add_status\n+    self.status = 1\n+    self.progress = 0\n+  end\n+\n+  def add_user_subject\n+    exist_record = UserSubject.where(user_course_id: self.id)\n+    self.user.subjects << self.course.subjects if exist_record.empty?\n+  end\n+\n+  def delete_user_subject\n+    delete = UserSubject.where(\"user_course_id = ?\", self.id)","path":"app/models/user_course.rb","position":23,"original_position":23,"commit_id":"0dfe9ac9fdad6978261371f09fd860f4a8550689","original_commit_id":"0dfe9ac9fdad6978261371f09fd860f4a8550689","user":{"login":"dieunb","id":2122175,"avatar_url":"https://avatars.githubusercontent.com/u/2122175?v=3","gravatar_id":"","url":"https://api.github.com/users/dieunb","html_url":"https://github.com/dieunb","followers_url":"https://api.github.com/users/dieunb/followers","following_url":"https://api.github.com/users/dieunb/following{/other_user}","gists_url":"https://api.github.com/users/dieunb/gists{/gist_id}","starred_url":"https://api.github.com/users/dieunb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dieunb/subscriptions","organizations_url":"https://api.github.com/users/dieunb/orgs","repos_url":"https://api.github.com/users/dieunb/repos","events_url":"https://api.github.com/users/dieunb/events{/privacy}","received_events_url":"https://api.github.com/users/dieunb/received_events","type":"User","site_admin":false},"body":"move to scope","created_at":"2015-03-11T08:56:00Z","updated_at":"2015-03-11T08:56:00Z","html_url":"https://github.com/framgia/tms_8/pull/18#discussion_r26196225","pull_request_url":"https://api.github.com/repos/framgia/tms_8/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/comments/26196225"},"html":{"href":"https://github.com/framgia/tms_8/pull/18#discussion_r26196225"},"pull_request":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/framgia/tms_8/pulls/18","id":30529835,"html_url":"https://github.com/framgia/tms_8/pull/18","diff_url":"https://github.com/framgia/tms_8/pull/18.diff","patch_url":"https://github.com/framgia/tms_8/pull/18.patch","issue_url":"https://api.github.com/repos/framgia/tms_8/issues/18","number":18,"state":"open","locked":false,"title":"submit model and controller","user":{"login":"Hoang-Tung","id":6307363,"avatar_url":"https://avatars.githubusercontent.com/u/6307363?v=3","gravatar_id":"","url":"https://api.github.com/users/Hoang-Tung","html_url":"https://github.com/Hoang-Tung","followers_url":"https://api.github.com/users/Hoang-Tung/followers","following_url":"https://api.github.com/users/Hoang-Tung/following{/other_user}","gists_url":"https://api.github.com/users/Hoang-Tung/gists{/gist_id}","starred_url":"https://api.github.com/users/Hoang-Tung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hoang-Tung/subscriptions","organizations_url":"https://api.github.com/users/Hoang-Tung/orgs","repos_url":"https://api.github.com/users/Hoang-Tung/repos","events_url":"https://api.github.com/users/Hoang-Tung/events{/privacy}","received_events_url":"https://api.github.com/users/Hoang-Tung/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-05T04:39:42Z","updated_at":"2015-03-11T08:56:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"56804c5ee1812501bbee62e57670e0efba5d8a20","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/framgia/tms_8/pulls/18/commits","review_comments_url":"https://api.github.com/repos/framgia/tms_8/pulls/18/comments","review_comment_url":"https://api.github.com/repos/framgia/tms_8/pulls/comments{/number}","comments_url":"https://api.github.com/repos/framgia/tms_8/issues/18/comments","statuses_url":"https://api.github.com/repos/framgia/tms_8/statuses/0dfe9ac9fdad6978261371f09fd860f4a8550689","head":{"label":"Hoang-Tung:nested_user_task_and_subject","ref":"nested_user_task_and_subject","sha":"0dfe9ac9fdad6978261371f09fd860f4a8550689","user":{"login":"Hoang-Tung","id":6307363,"avatar_url":"https://avatars.githubusercontent.com/u/6307363?v=3","gravatar_id":"","url":"https://api.github.com/users/Hoang-Tung","html_url":"https://github.com/Hoang-Tung","followers_url":"https://api.github.com/users/Hoang-Tung/followers","following_url":"https://api.github.com/users/Hoang-Tung/following{/other_user}","gists_url":"https://api.github.com/users/Hoang-Tung/gists{/gist_id}","starred_url":"https://api.github.com/users/Hoang-Tung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hoang-Tung/subscriptions","organizations_url":"https://api.github.com/users/Hoang-Tung/orgs","repos_url":"https://api.github.com/users/Hoang-Tung/repos","events_url":"https://api.github.com/users/Hoang-Tung/events{/privacy}","received_events_url":"https://api.github.com/users/Hoang-Tung/received_events","type":"User","site_admin":false},"repo":{"id":29842020,"name":"tms_8","full_name":"Hoang-Tung/tms_8","owner":{"login":"Hoang-Tung","id":6307363,"avatar_url":"https://avatars.githubusercontent.com/u/6307363?v=3","gravatar_id":"","url":"https://api.github.com/users/Hoang-Tung","html_url":"https://github.com/Hoang-Tung","followers_url":"https://api.github.com/users/Hoang-Tung/followers","following_url":"https://api.github.com/users/Hoang-Tung/following{/other_user}","gists_url":"https://api.github.com/users/Hoang-Tung/gists{/gist_id}","starred_url":"https://api.github.com/users/Hoang-Tung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hoang-Tung/subscriptions","organizations_url":"https://api.github.com/users/Hoang-Tung/orgs","repos_url":"https://api.github.com/users/Hoang-Tung/repos","events_url":"https://api.github.com/users/Hoang-Tung/events{/privacy}","received_events_url":"https://api.github.com/users/Hoang-Tung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Hoang-Tung/tms_8","description":"Framgia Training Management System (training)","fork":true,"url":"https://api.github.com/repos/Hoang-Tung/tms_8","forks_url":"https://api.github.com/repos/Hoang-Tung/tms_8/forks","keys_url":"https://api.github.com/repos/Hoang-Tung/tms_8/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Hoang-Tung/tms_8/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Hoang-Tung/tms_8/teams","hooks_url":"https://api.github.com/repos/Hoang-Tung/tms_8/hooks","issue_events_url":"https://api.github.com/repos/Hoang-Tung/tms_8/issues/events{/number}","events_url":"https://api.github.com/repos/Hoang-Tung/tms_8/events","assignees_url":"https://api.github.com/repos/Hoang-Tung/tms_8/assignees{/user}","branches_url":"https://api.github.com/repos/Hoang-Tung/tms_8/branches{/branch}","tags_url":"https://api.github.com/repos/Hoang-Tung/tms_8/tags","blobs_url":"https://api.github.com/repos/Hoang-Tung/tms_8/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Hoang-Tung/tms_8/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Hoang-Tung/tms_8/git/refs{/sha}","trees_url":"https://api.github.com/repos/Hoang-Tung/tms_8/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Hoang-Tung/tms_8/statuses/{sha}","languages_url":"https://api.github.com/repos/Hoang-Tung/tms_8/languages","stargazers_url":"https://api.github.com/repos/Hoang-Tung/tms_8/stargazers","contributors_url":"https://api.github.com/repos/Hoang-Tung/tms_8/contributors","subscribers_url":"https://api.github.com/repos/Hoang-Tung/tms_8/subscribers","subscription_url":"https://api.github.com/repos/Hoang-Tung/tms_8/subscription","commits_url":"https://api.github.com/repos/Hoang-Tung/tms_8/commits{/sha}","git_commits_url":"https://api.github.com/repos/Hoang-Tung/tms_8/git/commits{/sha}","comments_url":"https://api.github.com/repos/Hoang-Tung/tms_8/comments{/number}","issue_comment_url":"https://api.github.com/repos/Hoang-Tung/tms_8/issues/comments{/number}","contents_url":"https://api.github.com/repos/Hoang-Tung/tms_8/contents/{+path}","compare_url":"https://api.github.com/repos/Hoang-Tung/tms_8/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Hoang-Tung/tms_8/merges","archive_url":"https://api.github.com/repos/Hoang-Tung/tms_8/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Hoang-Tung/tms_8/downloads","issues_url":"https://api.github.com/repos/Hoang-Tung/tms_8/issues{/number}","pulls_url":"https://api.github.com/repos/Hoang-Tung/tms_8/pulls{/number}","milestones_url":"https://api.github.com/repos/Hoang-Tung/tms_8/milestones{/number}","notifications_url":"https://api.github.com/repos/Hoang-Tung/tms_8/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Hoang-Tung/tms_8/labels{/name}","releases_url":"https://api.github.com/repos/Hoang-Tung/tms_8/releases{/id}","created_at":"2015-01-26T02:46:42Z","updated_at":"2015-01-24T12:06:23Z","pushed_at":"2015-03-11T08:49:25Z","git_url":"git://github.com/Hoang-Tung/tms_8.git","ssh_url":"git@github.com:Hoang-Tung/tms_8.git","clone_url":"https://github.com/Hoang-Tung/tms_8.git","svn_url":"https://github.com/Hoang-Tung/tms_8","homepage":null,"size":261,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"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":"framgia:develop","ref":"develop","sha":"c8757d40677a71ca4b1bd669029ddf8f4c45b7b2","user":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"repo":{"id":29775300,"name":"tms_8","full_name":"framgia/tms_8","owner":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/framgia/tms_8","description":"Framgia Training Management System (training)","fork":false,"url":"https://api.github.com/repos/framgia/tms_8","forks_url":"https://api.github.com/repos/framgia/tms_8/forks","keys_url":"https://api.github.com/repos/framgia/tms_8/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framgia/tms_8/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framgia/tms_8/teams","hooks_url":"https://api.github.com/repos/framgia/tms_8/hooks","issue_events_url":"https://api.github.com/repos/framgia/tms_8/issues/events{/number}","events_url":"https://api.github.com/repos/framgia/tms_8/events","assignees_url":"https://api.github.com/repos/framgia/tms_8/assignees{/user}","branches_url":"https://api.github.com/repos/framgia/tms_8/branches{/branch}","tags_url":"https://api.github.com/repos/framgia/tms_8/tags","blobs_url":"https://api.github.com/repos/framgia/tms_8/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framgia/tms_8/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framgia/tms_8/git/refs{/sha}","trees_url":"https://api.github.com/repos/framgia/tms_8/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framgia/tms_8/statuses/{sha}","languages_url":"https://api.github.com/repos/framgia/tms_8/languages","stargazers_url":"https://api.github.com/repos/framgia/tms_8/stargazers","contributors_url":"https://api.github.com/repos/framgia/tms_8/contributors","subscribers_url":"https://api.github.com/repos/framgia/tms_8/subscribers","subscription_url":"https://api.github.com/repos/framgia/tms_8/subscription","commits_url":"https://api.github.com/repos/framgia/tms_8/commits{/sha}","git_commits_url":"https://api.github.com/repos/framgia/tms_8/git/commits{/sha}","comments_url":"https://api.github.com/repos/framgia/tms_8/comments{/number}","issue_comment_url":"https://api.github.com/repos/framgia/tms_8/issues/comments{/number}","contents_url":"https://api.github.com/repos/framgia/tms_8/contents/{+path}","compare_url":"https://api.github.com/repos/framgia/tms_8/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framgia/tms_8/merges","archive_url":"https://api.github.com/repos/framgia/tms_8/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framgia/tms_8/downloads","issues_url":"https://api.github.com/repos/framgia/tms_8/issues{/number}","pulls_url":"https://api.github.com/repos/framgia/tms_8/pulls{/number}","milestones_url":"https://api.github.com/repos/framgia/tms_8/milestones{/number}","notifications_url":"https://api.github.com/repos/framgia/tms_8/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framgia/tms_8/labels{/name}","releases_url":"https://api.github.com/repos/framgia/tms_8/releases{/id}","created_at":"2015-01-24T12:06:23Z","updated_at":"2015-01-24T12:06:23Z","pushed_at":"2015-02-27T06:57:35Z","git_url":"git://github.com/framgia/tms_8.git","ssh_url":"git@github.com:framgia/tms_8.git","clone_url":"https://github.com/framgia/tms_8.git","svn_url":"https://github.com/framgia/tms_8","homepage":null,"size":443,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":10,"forks":3,"open_issues":10,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/18"},"html":{"href":"https://github.com/framgia/tms_8/pull/18"},"issue":{"href":"https://api.github.com/repos/framgia/tms_8/issues/18"},"comments":{"href":"https://api.github.com/repos/framgia/tms_8/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/framgia/tms_8/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/framgia/tms_8/statuses/0dfe9ac9fdad6978261371f09fd860f4a8550689"}}}}