-
-
Save hanachin/b9bceb6f74ac3cb897b0 to your computer and use it in GitHub Desktop.
action resource
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 characters
# 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) | |
〜 | |
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 characters
Rails.application.routes.draw do | |
resources :posts do | |
scope controller: :post_actions do | |
member do | |
post :publish | |
post :hide | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment