-
-
Save hanachin/b9bceb6f74ac3cb897b0 to your computer and use it in GitHub Desktop.
Revisions
-
hanachin revised this gist
Mar 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # app/controllers/post_actions_controller.rb class PostActionsController < ApplicationController # POST /posts/:id/publish.json def publish if current_post.update(state: :publish, published_at: Time.zone.now) -
hanachin revised this gist
Mar 18, 2016 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # app/controllers/post_actions_controller.rb class PostsActionsController < ApplicationController # POST /posts/:id/publish.json def publish This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ Rails.application.routes.draw do resources :posts do scope controller: :post_actions do member do post :publish post :hide -
hanachin revised this gist
Mar 18, 2016 . 3 changed files with 33 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,26 @@ # app/controllers/posts_actions_controller.rb class PostsActionsController < ApplicationController # POST /posts/:id/publish.json def publish if current_post.update(state: :publish, published_at: Time.zone.now) 〜 else 〜 end end # POST /posts/:id/hide.json def hide if current_post.update(state: :hide, published_at: nil) 〜 else 〜 end end private def current_post Post.find(params[:id]) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ Rails.application.routes.draw do resources :posts do scope controller: :posts_actions do member do post :publish post :hide end end end end -
sinsoku revised this gist
Mar 18, 2016 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,11 @@ def save return false if invalid? @post = Post.find(post_id) if name == 'publish' @post.update state: :publish, published_at: Time.zone.now elsif name == 'xxx' # do something end # 適当にif分岐にしてるけど、本当はもう少しクラス設計を直して、if文がなくなるようにした方が良い end end -
sinsoku created this gist
Mar 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ # app/models/posts/action.rb class Action include ActiveModel::Model attr_reader :post_id, :name def save return false if invalid? @post = Post.find(post_id) # name の内容で処理を分岐したり、コールバックを書いたり。 end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # app/controllers/posts/actions_controller.rb module Posts class ActionsController < ApplicationController # POST /posts/:post_id/actions.json def create @action = Posts::Action.new(post_id: params[:post_id], name: params[:name]) respond_to do |format| if @action.save format.json { render json: @action, status: :created } else format.json { render json: @action.errors, status: :unprocessable_entity } else end end end end