{"action":"created","comment":{"url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/comments/29998023","id":29998023,"diff_hunk":"@@ -37,7 +36,39 @@ class Product < ActiveRecord::Base\n   accepts_nested_attributes_for :images, allow_destroy: true, :reject_if => :all_blank\n   belongs_to :cover, class_name: Image\n \n+  scope :recommends, -> { where(weight: 1).order(\"created_at desc\") }\n+\n+  before_save :check_premalink\n+\n   def cover_image\n     cover || images.first\n   end\n-end\n+\n+  # 立即购买，获取product第default variant的价格和ID\n+  def method_missing(name, *args, &black)\n+    method = \"#{name}\".gsub(\"buy_now_\", \"\")\n+    if[\"price\", \"id\"].include?(method)\n+      return variants.default_variant.try(method)\n+    end\n+    super\n+  end\n+\n+  private\n+\n+  def check_premalink\n+    if permalink.present?\n+      self.permalink.downcase!\n+      del_first_sprit\n+    end\n+    permalink_is_nil if permalink.blank?\n+    \n+  end\n+\n+  def permalink_is_nil\n+    self.permalink = Pinyin.t(name, splitter: \"\")\n+  end\n+\n+  def del_first_sprit\n+    self.permalink = permalink[1, permalink.length] if permalink.first == \"/\"\n+  end\n+end","path":"app/models/product.rb","position":53,"original_position":53,"commit_id":"61ca0debec286a7efd54e46d88c69e65b13f4111","original_commit_id":"61ca0debec286a7efd54e46d88c69e65b13f4111","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Final newline missing.","created_at":"2015-05-10T02:08:43Z","updated_at":"2015-05-10T02:08:43Z","html_url":"https://github.com/ZhaoZijie/calm/pull/22#discussion_r29998023","pull_request_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/ZhaoZijie/calm/pulls/comments/29998023"},"html":{"href":"https://github.com/ZhaoZijie/calm/pull/22#discussion_r29998023"},"pull_request":{"href":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22","id":35067248,"html_url":"https://github.com/ZhaoZijie/calm/pull/22","diff_url":"https://github.com/ZhaoZijie/calm/pull/22.diff","patch_url":"https://github.com/ZhaoZijie/calm/pull/22.patch","issue_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/22","number":22,"state":"open","locked":false,"title":"商品的推荐和置为精品","user":{"login":"clarkyi","id":1740702,"avatar_url":"https://avatars.githubusercontent.com/u/1740702?v=3","gravatar_id":"","url":"https://api.github.com/users/clarkyi","html_url":"https://github.com/clarkyi","followers_url":"https://api.github.com/users/clarkyi/followers","following_url":"https://api.github.com/users/clarkyi/following{/other_user}","gists_url":"https://api.github.com/users/clarkyi/gists{/gist_id}","starred_url":"https://api.github.com/users/clarkyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clarkyi/subscriptions","organizations_url":"https://api.github.com/users/clarkyi/orgs","repos_url":"https://api.github.com/users/clarkyi/repos","events_url":"https://api.github.com/users/clarkyi/events{/privacy}","received_events_url":"https://api.github.com/users/clarkyi/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-09T14:20:43Z","updated_at":"2015-05-10T02:08:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe2606d8fc555b9d4373399226d5066529a18329","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22/commits","review_comments_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22/comments","review_comment_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/22/comments","statuses_url":"https://api.github.com/repos/ZhaoZijie/calm/statuses/61ca0debec286a7efd54e46d88c69e65b13f4111","head":{"label":"ZhaoZijie:feature/show_product","ref":"feature/show_product","sha":"61ca0debec286a7efd54e46d88c69e65b13f4111","user":{"login":"ZhaoZijie","id":2377978,"avatar_url":"https://avatars.githubusercontent.com/u/2377978?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhaoZijie","html_url":"https://github.com/ZhaoZijie","followers_url":"https://api.github.com/users/ZhaoZijie/followers","following_url":"https://api.github.com/users/ZhaoZijie/following{/other_user}","gists_url":"https://api.github.com/users/ZhaoZijie/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhaoZijie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhaoZijie/subscriptions","organizations_url":"https://api.github.com/users/ZhaoZijie/orgs","repos_url":"https://api.github.com/users/ZhaoZijie/repos","events_url":"https://api.github.com/users/ZhaoZijie/events{/privacy}","received_events_url":"https://api.github.com/users/ZhaoZijie/received_events","type":"User","site_admin":false},"repo":{"id":30947407,"name":"calm","full_name":"ZhaoZijie/calm","owner":{"login":"ZhaoZijie","id":2377978,"avatar_url":"https://avatars.githubusercontent.com/u/2377978?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhaoZijie","html_url":"https://github.com/ZhaoZijie","followers_url":"https://api.github.com/users/ZhaoZijie/followers","following_url":"https://api.github.com/users/ZhaoZijie/following{/other_user}","gists_url":"https://api.github.com/users/ZhaoZijie/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhaoZijie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhaoZijie/subscriptions","organizations_url":"https://api.github.com/users/ZhaoZijie/orgs","repos_url":"https://api.github.com/users/ZhaoZijie/repos","events_url":"https://api.github.com/users/ZhaoZijie/events{/privacy}","received_events_url":"https://api.github.com/users/ZhaoZijie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ZhaoZijie/calm","description":"","fork":false,"url":"https://api.github.com/repos/ZhaoZijie/calm","forks_url":"https://api.github.com/repos/ZhaoZijie/calm/forks","keys_url":"https://api.github.com/repos/ZhaoZijie/calm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ZhaoZijie/calm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ZhaoZijie/calm/teams","hooks_url":"https://api.github.com/repos/ZhaoZijie/calm/hooks","issue_events_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/events{/number}","events_url":"https://api.github.com/repos/ZhaoZijie/calm/events","assignees_url":"https://api.github.com/repos/ZhaoZijie/calm/assignees{/user}","branches_url":"https://api.github.com/repos/ZhaoZijie/calm/branches{/branch}","tags_url":"https://api.github.com/repos/ZhaoZijie/calm/tags","blobs_url":"https://api.github.com/repos/ZhaoZijie/calm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ZhaoZijie/calm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ZhaoZijie/calm/git/refs{/sha}","trees_url":"https://api.github.com/repos/ZhaoZijie/calm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ZhaoZijie/calm/statuses/{sha}","languages_url":"https://api.github.com/repos/ZhaoZijie/calm/languages","stargazers_url":"https://api.github.com/repos/ZhaoZijie/calm/stargazers","contributors_url":"https://api.github.com/repos/ZhaoZijie/calm/contributors","subscribers_url":"https://api.github.com/repos/ZhaoZijie/calm/subscribers","subscription_url":"https://api.github.com/repos/ZhaoZijie/calm/subscription","commits_url":"https://api.github.com/repos/ZhaoZijie/calm/commits{/sha}","git_commits_url":"https://api.github.com/repos/ZhaoZijie/calm/git/commits{/sha}","comments_url":"https://api.github.com/repos/ZhaoZijie/calm/comments{/number}","issue_comment_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/comments{/number}","contents_url":"https://api.github.com/repos/ZhaoZijie/calm/contents/{+path}","compare_url":"https://api.github.com/repos/ZhaoZijie/calm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ZhaoZijie/calm/merges","archive_url":"https://api.github.com/repos/ZhaoZijie/calm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ZhaoZijie/calm/downloads","issues_url":"https://api.github.com/repos/ZhaoZijie/calm/issues{/number}","pulls_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls{/number}","milestones_url":"https://api.github.com/repos/ZhaoZijie/calm/milestones{/number}","notifications_url":"https://api.github.com/repos/ZhaoZijie/calm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ZhaoZijie/calm/labels{/name}","releases_url":"https://api.github.com/repos/ZhaoZijie/calm/releases{/id}","created_at":"2015-02-18T01:36:49Z","updated_at":"2015-05-05T05:21:14Z","pushed_at":"2015-05-10T02:08:39Z","git_url":"git://github.com/ZhaoZijie/calm.git","ssh_url":"git@github.com:ZhaoZijie/calm.git","clone_url":"https://github.com/ZhaoZijie/calm.git","svn_url":"https://github.com/ZhaoZijie/calm","homepage":null,"size":4958,"stargazers_count":0,"watchers_count":0,"language":"HTML","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":"ZhaoZijie:master","ref":"master","sha":"e84232713e2f3add3a3a42447ff8bcd52c6a0fe1","user":{"login":"ZhaoZijie","id":2377978,"avatar_url":"https://avatars.githubusercontent.com/u/2377978?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhaoZijie","html_url":"https://github.com/ZhaoZijie","followers_url":"https://api.github.com/users/ZhaoZijie/followers","following_url":"https://api.github.com/users/ZhaoZijie/following{/other_user}","gists_url":"https://api.github.com/users/ZhaoZijie/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhaoZijie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhaoZijie/subscriptions","organizations_url":"https://api.github.com/users/ZhaoZijie/orgs","repos_url":"https://api.github.com/users/ZhaoZijie/repos","events_url":"https://api.github.com/users/ZhaoZijie/events{/privacy}","received_events_url":"https://api.github.com/users/ZhaoZijie/received_events","type":"User","site_admin":false},"repo":{"id":30947407,"name":"calm","full_name":"ZhaoZijie/calm","owner":{"login":"ZhaoZijie","id":2377978,"avatar_url":"https://avatars.githubusercontent.com/u/2377978?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhaoZijie","html_url":"https://github.com/ZhaoZijie","followers_url":"https://api.github.com/users/ZhaoZijie/followers","following_url":"https://api.github.com/users/ZhaoZijie/following{/other_user}","gists_url":"https://api.github.com/users/ZhaoZijie/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhaoZijie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhaoZijie/subscriptions","organizations_url":"https://api.github.com/users/ZhaoZijie/orgs","repos_url":"https://api.github.com/users/ZhaoZijie/repos","events_url":"https://api.github.com/users/ZhaoZijie/events{/privacy}","received_events_url":"https://api.github.com/users/ZhaoZijie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ZhaoZijie/calm","description":"","fork":false,"url":"https://api.github.com/repos/ZhaoZijie/calm","forks_url":"https://api.github.com/repos/ZhaoZijie/calm/forks","keys_url":"https://api.github.com/repos/ZhaoZijie/calm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ZhaoZijie/calm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ZhaoZijie/calm/teams","hooks_url":"https://api.github.com/repos/ZhaoZijie/calm/hooks","issue_events_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/events{/number}","events_url":"https://api.github.com/repos/ZhaoZijie/calm/events","assignees_url":"https://api.github.com/repos/ZhaoZijie/calm/assignees{/user}","branches_url":"https://api.github.com/repos/ZhaoZijie/calm/branches{/branch}","tags_url":"https://api.github.com/repos/ZhaoZijie/calm/tags","blobs_url":"https://api.github.com/repos/ZhaoZijie/calm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ZhaoZijie/calm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ZhaoZijie/calm/git/refs{/sha}","trees_url":"https://api.github.com/repos/ZhaoZijie/calm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ZhaoZijie/calm/statuses/{sha}","languages_url":"https://api.github.com/repos/ZhaoZijie/calm/languages","stargazers_url":"https://api.github.com/repos/ZhaoZijie/calm/stargazers","contributors_url":"https://api.github.com/repos/ZhaoZijie/calm/contributors","subscribers_url":"https://api.github.com/repos/ZhaoZijie/calm/subscribers","subscription_url":"https://api.github.com/repos/ZhaoZijie/calm/subscription","commits_url":"https://api.github.com/repos/ZhaoZijie/calm/commits{/sha}","git_commits_url":"https://api.github.com/repos/ZhaoZijie/calm/git/commits{/sha}","comments_url":"https://api.github.com/repos/ZhaoZijie/calm/comments{/number}","issue_comment_url":"https://api.github.com/repos/ZhaoZijie/calm/issues/comments{/number}","contents_url":"https://api.github.com/repos/ZhaoZijie/calm/contents/{+path}","compare_url":"https://api.github.com/repos/ZhaoZijie/calm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ZhaoZijie/calm/merges","archive_url":"https://api.github.com/repos/ZhaoZijie/calm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ZhaoZijie/calm/downloads","issues_url":"https://api.github.com/repos/ZhaoZijie/calm/issues{/number}","pulls_url":"https://api.github.com/repos/ZhaoZijie/calm/pulls{/number}","milestones_url":"https://api.github.com/repos/ZhaoZijie/calm/milestones{/number}","notifications_url":"https://api.github.com/repos/ZhaoZijie/calm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ZhaoZijie/calm/labels{/name}","releases_url":"https://api.github.com/repos/ZhaoZijie/calm/releases{/id}","created_at":"2015-02-18T01:36:49Z","updated_at":"2015-05-05T05:21:14Z","pushed_at":"2015-05-10T02:08:39Z","git_url":"git://github.com/ZhaoZijie/calm.git","ssh_url":"git@github.com:ZhaoZijie/calm.git","clone_url":"https://github.com/ZhaoZijie/calm.git","svn_url":"https://github.com/ZhaoZijie/calm","homepage":null,"size":4958,"stargazers_count":0,"watchers_count":0,"language":"HTML","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/ZhaoZijie/calm/pulls/22"},"html":{"href":"https://github.com/ZhaoZijie/calm/pull/22"},"issue":{"href":"https://api.github.com/repos/ZhaoZijie/calm/issues/22"},"comments":{"href":"https://api.github.com/repos/ZhaoZijie/calm/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/ZhaoZijie/calm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ZhaoZijie/calm/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/ZhaoZijie/calm/statuses/61ca0debec286a7efd54e46d88c69e65b13f4111"}}}}