{"action":"created","comment":{"url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/comments/35509654","id":35509654,"diff_hunk":"@@ -1,22 +1,95 @@\n class PrototypesController < ApplicationController\n   def index\n+    @prototypes = Prototype.order('title ASC').page(params[:page]).per(3)\n   end\n \n   def show\n+    @prototype = Prototype.find(params[:id])\n+    @user = @prototype.user\n+    @new_comment = Comment.new\n+    @like = Like.find_or_init(current_user.id, params[:id])\n   end\n \n   def new\n+    @prototype = Prototype.new\n+    @prototype.thumbnails.build\n   end\n \n   def create\n+    prototype = current_user.prototypes.new(prototype_params)\n+    prototype.tag_list << tags_params\n+    if prototype.save\n+      # save thumbnails for both main & sub\n+      thumbnails_params.each do |k, v|\n+        if k == \"main\"\n+          prototype.thumbnails.main.create(thumbnail: v)\n+        else\n+          prototype.thumbnails.sub.create(thumbnail: v)\n+        end\n+      end\n+\n+      flash[:success] = \"Successfully created your prototype.\"\n+      redirect_to newest_prototypes_path\n+    else\n+      flash[:warning] = \"Unfortunately failed to save.\"\n+      render :new\n+    end\n   end\n \n   def edit\n+    @prototype = Prototype.find(params[:id])\n+    @tag_names = @prototype.tag_list\n+    if @prototype.user_id != current_user.id\n+      flash[:danger] = \"Access denied.\"\n+      redirect_to root_path\n+    end\n   end\n \n   def update\n+    binding.pry\n+    prototype = Prototype.find(params[:id])\n+    prototype.tag_list = tags_params\n+    if prototype.update(prototype_params)\n+      # reset thumbnails for update\n+      prototype.thumbnails.each(&:destroy)\n+      # save thumbnails for both main & sub\n+      thumbnails_params.each do |k, v|\n+        if k == \"main\"\n+          prototype.thumbnails.main.create(thumbnail: v)\n+        else\n+          prototype.thumbnails.sub.create(thumbnail: v)\n+        end\n+      end\n+\n+      flash[:success] = \"Successfully updated your prototype.\"\n+      redirect_to newest_prototypes_path\n+    else\n+      flash[:warning] = \"Unfortunately failed to update.\"\n+      render :edit\n+    end\n+  end\n+\n+  def newest\n+    @prototypes = Prototype.order('created_at DESC').page(params[:page]).per(3)\n+    render :index\n+  end\n+\n+  def popular\n+    @prototypes = Prototype.order('likes_count DESC').page(params[:page]).per(3)\n+    render :index\n+  end\n+\n+  private\n+\n+  def prototype_params\n+    params.require(:prototype).permit(:title, :copy, :concept)\n+  end\n+\n+  def thumbnails_params\n+    params.require(:prototype).require(:thumbnails_attributes).require(\"0\")\n   end\n \n-  def destroy\n+  def tags_params\n+    params.require(:prototype).require(:tags).map{|k,v| v }\n   end","path":"app/controllers/prototypes_controller.rb","position":68,"original_position":95,"commit_id":"1f4d0de4cd739a985dad5e25fef89ee30272cf11","original_commit_id":"3c41b087777a9b692433ff1ea2f06f45a0cccbbb","user":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"body":"> prototypeモデルに対してtag_listというパラメーターに値を指定すると、保存することを知っていたので、一度モデルと関係しないtext_field_tagを利用して、値だけ送り整形しあとでmergeする処理をしました。\r\n\r\nなるほどですね！スッキリしました！\r\nそのためにtext_field_tagで値だけパラメーターとして送っていたと👀！","created_at":"2015-07-27T07:01:30Z","updated_at":"2015-07-27T07:01:30Z","html_url":"https://github.com/Yama-to/ymtSpace/pull/6#discussion_r35509654","pull_request_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/comments/35509654"},"html":{"href":"https://github.com/Yama-to/ymtSpace/pull/6#discussion_r35509654"},"pull_request":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6","id":40831257,"html_url":"https://github.com/Yama-to/ymtSpace/pull/6","diff_url":"https://github.com/Yama-to/ymtSpace/pull/6.diff","patch_url":"https://github.com/Yama-to/ymtSpace/pull/6.patch","issue_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/6","number":6,"state":"open","locked":false,"title":"Create prototype functions","user":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"body":"- Define methods in a model:prototype.rb\r\n- Make forms for thumbnails & tags nested\r\n- Create preview function for images before uploading\r\n- Set flash messages\r\n- Fix bootstrap design and draw new styles (as seen in later PR)","created_at":"2015-07-25T05:10:18Z","updated_at":"2015-07-27T07:01:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3f13328b225d355fd0126fa616026f1f019e67c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6/commits","review_comments_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6/comments","review_comment_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/6/comments","statuses_url":"https://api.github.com/repos/Yama-to/ymtSpace/statuses/1f4d0de4cd739a985dad5e25fef89ee30272cf11","head":{"label":"Yama-to:create_prototype_functions","ref":"create_prototype_functions","sha":"1f4d0de4cd739a985dad5e25fef89ee30272cf11","user":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"repo":{"id":39078247,"name":"ymtSpace","full_name":"Yama-to/ymtSpace","owner":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Yama-to/ymtSpace","description":"[DEMO] first beta version of prototyping sharing service, which authorized by we-b inc.,","fork":false,"url":"https://api.github.com/repos/Yama-to/ymtSpace","forks_url":"https://api.github.com/repos/Yama-to/ymtSpace/forks","keys_url":"https://api.github.com/repos/Yama-to/ymtSpace/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yama-to/ymtSpace/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yama-to/ymtSpace/teams","hooks_url":"https://api.github.com/repos/Yama-to/ymtSpace/hooks","issue_events_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/events{/number}","events_url":"https://api.github.com/repos/Yama-to/ymtSpace/events","assignees_url":"https://api.github.com/repos/Yama-to/ymtSpace/assignees{/user}","branches_url":"https://api.github.com/repos/Yama-to/ymtSpace/branches{/branch}","tags_url":"https://api.github.com/repos/Yama-to/ymtSpace/tags","blobs_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yama-to/ymtSpace/statuses/{sha}","languages_url":"https://api.github.com/repos/Yama-to/ymtSpace/languages","stargazers_url":"https://api.github.com/repos/Yama-to/ymtSpace/stargazers","contributors_url":"https://api.github.com/repos/Yama-to/ymtSpace/contributors","subscribers_url":"https://api.github.com/repos/Yama-to/ymtSpace/subscribers","subscription_url":"https://api.github.com/repos/Yama-to/ymtSpace/subscription","commits_url":"https://api.github.com/repos/Yama-to/ymtSpace/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yama-to/ymtSpace/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yama-to/ymtSpace/contents/{+path}","compare_url":"https://api.github.com/repos/Yama-to/ymtSpace/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yama-to/ymtSpace/merges","archive_url":"https://api.github.com/repos/Yama-to/ymtSpace/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yama-to/ymtSpace/downloads","issues_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues{/number}","pulls_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls{/number}","milestones_url":"https://api.github.com/repos/Yama-to/ymtSpace/milestones{/number}","notifications_url":"https://api.github.com/repos/Yama-to/ymtSpace/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yama-to/ymtSpace/labels{/name}","releases_url":"https://api.github.com/repos/Yama-to/ymtSpace/releases{/id}","created_at":"2015-07-14T14:04:18Z","updated_at":"2015-07-14T14:06:16Z","pushed_at":"2015-07-26T04:28:28Z","git_url":"git://github.com/Yama-to/ymtSpace.git","ssh_url":"git@github.com:Yama-to/ymtSpace.git","clone_url":"https://github.com/Yama-to/ymtSpace.git","svn_url":"https://github.com/Yama-to/ymtSpace","homepage":null,"size":732,"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":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"Yama-to:master","ref":"master","sha":"27d1876e285f86f2da5ac14c453aff19a0b62a78","user":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"repo":{"id":39078247,"name":"ymtSpace","full_name":"Yama-to/ymtSpace","owner":{"login":"Yama-to","id":11901022,"avatar_url":"https://avatars.githubusercontent.com/u/11901022?v=3","gravatar_id":"","url":"https://api.github.com/users/Yama-to","html_url":"https://github.com/Yama-to","followers_url":"https://api.github.com/users/Yama-to/followers","following_url":"https://api.github.com/users/Yama-to/following{/other_user}","gists_url":"https://api.github.com/users/Yama-to/gists{/gist_id}","starred_url":"https://api.github.com/users/Yama-to/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yama-to/subscriptions","organizations_url":"https://api.github.com/users/Yama-to/orgs","repos_url":"https://api.github.com/users/Yama-to/repos","events_url":"https://api.github.com/users/Yama-to/events{/privacy}","received_events_url":"https://api.github.com/users/Yama-to/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Yama-to/ymtSpace","description":"[DEMO] first beta version of prototyping sharing service, which authorized by we-b inc.,","fork":false,"url":"https://api.github.com/repos/Yama-to/ymtSpace","forks_url":"https://api.github.com/repos/Yama-to/ymtSpace/forks","keys_url":"https://api.github.com/repos/Yama-to/ymtSpace/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yama-to/ymtSpace/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yama-to/ymtSpace/teams","hooks_url":"https://api.github.com/repos/Yama-to/ymtSpace/hooks","issue_events_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/events{/number}","events_url":"https://api.github.com/repos/Yama-to/ymtSpace/events","assignees_url":"https://api.github.com/repos/Yama-to/ymtSpace/assignees{/user}","branches_url":"https://api.github.com/repos/Yama-to/ymtSpace/branches{/branch}","tags_url":"https://api.github.com/repos/Yama-to/ymtSpace/tags","blobs_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yama-to/ymtSpace/statuses/{sha}","languages_url":"https://api.github.com/repos/Yama-to/ymtSpace/languages","stargazers_url":"https://api.github.com/repos/Yama-to/ymtSpace/stargazers","contributors_url":"https://api.github.com/repos/Yama-to/ymtSpace/contributors","subscribers_url":"https://api.github.com/repos/Yama-to/ymtSpace/subscribers","subscription_url":"https://api.github.com/repos/Yama-to/ymtSpace/subscription","commits_url":"https://api.github.com/repos/Yama-to/ymtSpace/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yama-to/ymtSpace/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yama-to/ymtSpace/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yama-to/ymtSpace/contents/{+path}","compare_url":"https://api.github.com/repos/Yama-to/ymtSpace/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yama-to/ymtSpace/merges","archive_url":"https://api.github.com/repos/Yama-to/ymtSpace/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yama-to/ymtSpace/downloads","issues_url":"https://api.github.com/repos/Yama-to/ymtSpace/issues{/number}","pulls_url":"https://api.github.com/repos/Yama-to/ymtSpace/pulls{/number}","milestones_url":"https://api.github.com/repos/Yama-to/ymtSpace/milestones{/number}","notifications_url":"https://api.github.com/repos/Yama-to/ymtSpace/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yama-to/ymtSpace/labels{/name}","releases_url":"https://api.github.com/repos/Yama-to/ymtSpace/releases{/id}","created_at":"2015-07-14T14:04:18Z","updated_at":"2015-07-14T14:06:16Z","pushed_at":"2015-07-26T04:28:28Z","git_url":"git://github.com/Yama-to/ymtSpace.git","ssh_url":"git@github.com:Yama-to/ymtSpace.git","clone_url":"https://github.com/Yama-to/ymtSpace.git","svn_url":"https://github.com/Yama-to/ymtSpace","homepage":null,"size":732,"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":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6"},"html":{"href":"https://github.com/Yama-to/ymtSpace/pull/6"},"issue":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/issues/6"},"comments":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/Yama-to/ymtSpace/statuses/1f4d0de4cd739a985dad5e25fef89ee30272cf11"}}}}