{"action":"created","comment":{"url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/comments/24077461","id":24077461,"diff_hunk":"@@ -1,14 +1,39 @@\n class Post < ActiveRecord::Base\n   has_many :comments, dependent: :destroy\n+  has_many :votes, dependent: :destroy\n   belongs_to :user\n   belongs_to :topic\n   mount_uploader :image, ImageUploader\n+  after_create :create_vote\n+  validates :title, length: { minimum: 5 }, presence: true\n+  validates :body, length: { minimum: 20 }, presence: true\n+  # validates :topic, presence: true\n+  # validates :user, presence: true\n \n+  def up_votes\n+    votes.where(value: 1).count\n+  end\n \n-  default_scope { order('created_at DESC') }\n+  def down_votes\n+    votes.where(value: -1).count\n+  end\n \n-  validates :title, length: { minimum: 5 }, presence: true\n-  validates :body, length: { minimum: 20 }, presence: true\n-  validates :topic, presence: true\n-  validates :user, presence: true\n+  def points\n+    votes.sum(:value)\n+  end\n+\n+  def update_rank\n+    age_in_days = (created_at - Time.new(1970,1,1)) / (60 * 60 * 24)\n+    new_rank = points + age_in_days\n+\n+    update_attribute(:rank, new_rank)\n+  end\n+\n+  default_scope { order('rank DESC') }\n+\n+  private\n+\n+  def create_vote\n+    votes.create(value: 1, post: self)","path":"app/models/post.rb","position":42,"original_position":42,"commit_id":"86d046ae8f892b9867ebc900ee8a522ec816f949","original_commit_id":"86d046ae8f892b9867ebc900ee8a522ec816f949","user":{"login":"eliotsykes","id":31698,"avatar_url":"https://avatars.githubusercontent.com/u/31698?v=3","gravatar_id":"","url":"https://api.github.com/users/eliotsykes","html_url":"https://github.com/eliotsykes","followers_url":"https://api.github.com/users/eliotsykes/followers","following_url":"https://api.github.com/users/eliotsykes/following{/other_user}","gists_url":"https://api.github.com/users/eliotsykes/gists{/gist_id}","starred_url":"https://api.github.com/users/eliotsykes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliotsykes/subscriptions","organizations_url":"https://api.github.com/users/eliotsykes/orgs","repos_url":"https://api.github.com/users/eliotsykes/repos","events_url":"https://api.github.com/users/eliotsykes/events{/privacy}","received_events_url":"https://api.github.com/users/eliotsykes/received_events","type":"User","site_admin":false},"body":"Try this, with the leading `user.` and see if the errors are as expected:\r\n```ruby\r\nuser.votes.create(value: 1, post: self)\r\n```","created_at":"2015-02-04T11:38:59Z","updated_at":"2015-02-04T11:38:59Z","html_url":"https://github.com/dannyvassallo/bloccit/pull/9#discussion_r24077461","pull_request_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/comments/24077461"},"html":{"href":"https://github.com/dannyvassallo/bloccit/pull/9#discussion_r24077461"},"pull_request":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9","id":28442224,"html_url":"https://github.com/dannyvassallo/bloccit/pull/9","diff_url":"https://github.com/dannyvassallo/bloccit/pull/9.diff","patch_url":"https://github.com/dannyvassallo/bloccit/pull/9.patch","issue_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/9","number":9,"state":"closed","locked":false,"title":"Creating votes","user":{"login":"dannyvassallo","id":5847215,"avatar_url":"https://avatars.githubusercontent.com/u/5847215?v=3","gravatar_id":"","url":"https://api.github.com/users/dannyvassallo","html_url":"https://github.com/dannyvassallo","followers_url":"https://api.github.com/users/dannyvassallo/followers","following_url":"https://api.github.com/users/dannyvassallo/following{/other_user}","gists_url":"https://api.github.com/users/dannyvassallo/gists{/gist_id}","starred_url":"https://api.github.com/users/dannyvassallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dannyvassallo/subscriptions","organizations_url":"https://api.github.com/users/dannyvassallo/orgs","repos_url":"https://api.github.com/users/dannyvassallo/repos","events_url":"https://api.github.com/users/dannyvassallo/events{/privacy}","received_events_url":"https://api.github.com/users/dannyvassallo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-02T02:41:11Z","updated_at":"2015-02-04T11:38:59Z","closed_at":"2015-02-04T04:04:58Z","merged_at":"2015-02-04T04:04:58Z","merge_commit_sha":"35a872dbe5251152a50cc7c7a1cb38de25e9af58","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9/commits","review_comments_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9/comments","review_comment_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/comments/{number}","comments_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/9/comments","statuses_url":"https://api.github.com/repos/dannyvassallo/bloccit/statuses/86d046ae8f892b9867ebc900ee8a522ec816f949","head":{"label":"dannyvassallo:creating-votes","ref":"creating-votes","sha":"86d046ae8f892b9867ebc900ee8a522ec816f949","user":{"login":"dannyvassallo","id":5847215,"avatar_url":"https://avatars.githubusercontent.com/u/5847215?v=3","gravatar_id":"","url":"https://api.github.com/users/dannyvassallo","html_url":"https://github.com/dannyvassallo","followers_url":"https://api.github.com/users/dannyvassallo/followers","following_url":"https://api.github.com/users/dannyvassallo/following{/other_user}","gists_url":"https://api.github.com/users/dannyvassallo/gists{/gist_id}","starred_url":"https://api.github.com/users/dannyvassallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dannyvassallo/subscriptions","organizations_url":"https://api.github.com/users/dannyvassallo/orgs","repos_url":"https://api.github.com/users/dannyvassallo/repos","events_url":"https://api.github.com/users/dannyvassallo/events{/privacy}","received_events_url":"https://api.github.com/users/dannyvassallo/received_events","type":"User","site_admin":false},"repo":{"id":28119196,"name":"bloccit","full_name":"dannyvassallo/bloccit","owner":{"login":"dannyvassallo","id":5847215,"avatar_url":"https://avatars.githubusercontent.com/u/5847215?v=3","gravatar_id":"","url":"https://api.github.com/users/dannyvassallo","html_url":"https://github.com/dannyvassallo","followers_url":"https://api.github.com/users/dannyvassallo/followers","following_url":"https://api.github.com/users/dannyvassallo/following{/other_user}","gists_url":"https://api.github.com/users/dannyvassallo/gists{/gist_id}","starred_url":"https://api.github.com/users/dannyvassallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dannyvassallo/subscriptions","organizations_url":"https://api.github.com/users/dannyvassallo/orgs","repos_url":"https://api.github.com/users/dannyvassallo/repos","events_url":"https://api.github.com/users/dannyvassallo/events{/privacy}","received_events_url":"https://api.github.com/users/dannyvassallo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dannyvassallo/bloccit","description":"","fork":false,"url":"https://api.github.com/repos/dannyvassallo/bloccit","forks_url":"https://api.github.com/repos/dannyvassallo/bloccit/forks","keys_url":"https://api.github.com/repos/dannyvassallo/bloccit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dannyvassallo/bloccit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dannyvassallo/bloccit/teams","hooks_url":"https://api.github.com/repos/dannyvassallo/bloccit/hooks","issue_events_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/events{/number}","events_url":"https://api.github.com/repos/dannyvassallo/bloccit/events","assignees_url":"https://api.github.com/repos/dannyvassallo/bloccit/assignees{/user}","branches_url":"https://api.github.com/repos/dannyvassallo/bloccit/branches{/branch}","tags_url":"https://api.github.com/repos/dannyvassallo/bloccit/tags","blobs_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/refs{/sha}","trees_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dannyvassallo/bloccit/statuses/{sha}","languages_url":"https://api.github.com/repos/dannyvassallo/bloccit/languages","stargazers_url":"https://api.github.com/repos/dannyvassallo/bloccit/stargazers","contributors_url":"https://api.github.com/repos/dannyvassallo/bloccit/contributors","subscribers_url":"https://api.github.com/repos/dannyvassallo/bloccit/subscribers","subscription_url":"https://api.github.com/repos/dannyvassallo/bloccit/subscription","commits_url":"https://api.github.com/repos/dannyvassallo/bloccit/commits{/sha}","git_commits_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/commits{/sha}","comments_url":"https://api.github.com/repos/dannyvassallo/bloccit/comments{/number}","issue_comment_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/comments/{number}","contents_url":"https://api.github.com/repos/dannyvassallo/bloccit/contents/{+path}","compare_url":"https://api.github.com/repos/dannyvassallo/bloccit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dannyvassallo/bloccit/merges","archive_url":"https://api.github.com/repos/dannyvassallo/bloccit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dannyvassallo/bloccit/downloads","issues_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues{/number}","pulls_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls{/number}","milestones_url":"https://api.github.com/repos/dannyvassallo/bloccit/milestones{/number}","notifications_url":"https://api.github.com/repos/dannyvassallo/bloccit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dannyvassallo/bloccit/labels{/name}","releases_url":"https://api.github.com/repos/dannyvassallo/bloccit/releases{/id}","created_at":"2014-12-17T03:23:57Z","updated_at":"2015-02-04T04:04:58Z","pushed_at":"2015-02-04T04:04:58Z","git_url":"git://github.com/dannyvassallo/bloccit.git","ssh_url":"git@github.com:dannyvassallo/bloccit.git","clone_url":"https://github.com/dannyvassallo/bloccit.git","svn_url":"https://github.com/dannyvassallo/bloccit","homepage":null,"size":804,"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":"dannyvassallo:master","ref":"master","sha":"6408307306c667fd941388a908da310c5ad85bcf","user":{"login":"dannyvassallo","id":5847215,"avatar_url":"https://avatars.githubusercontent.com/u/5847215?v=3","gravatar_id":"","url":"https://api.github.com/users/dannyvassallo","html_url":"https://github.com/dannyvassallo","followers_url":"https://api.github.com/users/dannyvassallo/followers","following_url":"https://api.github.com/users/dannyvassallo/following{/other_user}","gists_url":"https://api.github.com/users/dannyvassallo/gists{/gist_id}","starred_url":"https://api.github.com/users/dannyvassallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dannyvassallo/subscriptions","organizations_url":"https://api.github.com/users/dannyvassallo/orgs","repos_url":"https://api.github.com/users/dannyvassallo/repos","events_url":"https://api.github.com/users/dannyvassallo/events{/privacy}","received_events_url":"https://api.github.com/users/dannyvassallo/received_events","type":"User","site_admin":false},"repo":{"id":28119196,"name":"bloccit","full_name":"dannyvassallo/bloccit","owner":{"login":"dannyvassallo","id":5847215,"avatar_url":"https://avatars.githubusercontent.com/u/5847215?v=3","gravatar_id":"","url":"https://api.github.com/users/dannyvassallo","html_url":"https://github.com/dannyvassallo","followers_url":"https://api.github.com/users/dannyvassallo/followers","following_url":"https://api.github.com/users/dannyvassallo/following{/other_user}","gists_url":"https://api.github.com/users/dannyvassallo/gists{/gist_id}","starred_url":"https://api.github.com/users/dannyvassallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dannyvassallo/subscriptions","organizations_url":"https://api.github.com/users/dannyvassallo/orgs","repos_url":"https://api.github.com/users/dannyvassallo/repos","events_url":"https://api.github.com/users/dannyvassallo/events{/privacy}","received_events_url":"https://api.github.com/users/dannyvassallo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dannyvassallo/bloccit","description":"","fork":false,"url":"https://api.github.com/repos/dannyvassallo/bloccit","forks_url":"https://api.github.com/repos/dannyvassallo/bloccit/forks","keys_url":"https://api.github.com/repos/dannyvassallo/bloccit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dannyvassallo/bloccit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dannyvassallo/bloccit/teams","hooks_url":"https://api.github.com/repos/dannyvassallo/bloccit/hooks","issue_events_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/events{/number}","events_url":"https://api.github.com/repos/dannyvassallo/bloccit/events","assignees_url":"https://api.github.com/repos/dannyvassallo/bloccit/assignees{/user}","branches_url":"https://api.github.com/repos/dannyvassallo/bloccit/branches{/branch}","tags_url":"https://api.github.com/repos/dannyvassallo/bloccit/tags","blobs_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/refs{/sha}","trees_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dannyvassallo/bloccit/statuses/{sha}","languages_url":"https://api.github.com/repos/dannyvassallo/bloccit/languages","stargazers_url":"https://api.github.com/repos/dannyvassallo/bloccit/stargazers","contributors_url":"https://api.github.com/repos/dannyvassallo/bloccit/contributors","subscribers_url":"https://api.github.com/repos/dannyvassallo/bloccit/subscribers","subscription_url":"https://api.github.com/repos/dannyvassallo/bloccit/subscription","commits_url":"https://api.github.com/repos/dannyvassallo/bloccit/commits{/sha}","git_commits_url":"https://api.github.com/repos/dannyvassallo/bloccit/git/commits{/sha}","comments_url":"https://api.github.com/repos/dannyvassallo/bloccit/comments{/number}","issue_comment_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues/comments/{number}","contents_url":"https://api.github.com/repos/dannyvassallo/bloccit/contents/{+path}","compare_url":"https://api.github.com/repos/dannyvassallo/bloccit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dannyvassallo/bloccit/merges","archive_url":"https://api.github.com/repos/dannyvassallo/bloccit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dannyvassallo/bloccit/downloads","issues_url":"https://api.github.com/repos/dannyvassallo/bloccit/issues{/number}","pulls_url":"https://api.github.com/repos/dannyvassallo/bloccit/pulls{/number}","milestones_url":"https://api.github.com/repos/dannyvassallo/bloccit/milestones{/number}","notifications_url":"https://api.github.com/repos/dannyvassallo/bloccit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dannyvassallo/bloccit/labels{/name}","releases_url":"https://api.github.com/repos/dannyvassallo/bloccit/releases{/id}","created_at":"2014-12-17T03:23:57Z","updated_at":"2015-02-04T04:04:58Z","pushed_at":"2015-02-04T04:04:58Z","git_url":"git://github.com/dannyvassallo/bloccit.git","ssh_url":"git@github.com:dannyvassallo/bloccit.git","clone_url":"https://github.com/dannyvassallo/bloccit.git","svn_url":"https://github.com/dannyvassallo/bloccit","homepage":null,"size":804,"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/dannyvassallo/bloccit/pulls/9"},"html":{"href":"https://github.com/dannyvassallo/bloccit/pull/9"},"issue":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/issues/9"},"comments":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/dannyvassallo/bloccit/statuses/86d046ae8f892b9867ebc900ee8a522ec816f949"}}}}