Skip to content

Instantly share code, notes, and snippets.

@hanachin
Forked from sinsoku/action.rb
Last active March 18, 2016 15:15
Show Gist options
  • Save hanachin/b9bceb6f74ac3cb897b0 to your computer and use it in GitHub Desktop.
Save hanachin/b9bceb6f74ac3cb897b0 to your computer and use it in GitHub Desktop.
action resource
# 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
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