项目作者: alexandercsmith

项目描述 :
Publishing Module [PRE-GEM-CONCEPT]
高级语言: Ruby
项目地址: git://github.com/alexandercsmith/publishing.git
创建时间: 2019-02-09T00:48:06Z
项目社区:https://github.com/alexandercsmith/publishing

开源协议:

下载


hackerbrief# Publishing

Publishing Module for Ruby on Rails Model’s.

  • Publish Records with a Boolean and Datetime
  • When making Edits and Publishing again, Datetime value is not updated

Install

Location of Module

  1. ~/app/models/concerns/publishing.rb

Migration to Model

  1. $ rails g migration AddPublishingTo{MODEL} published:boolean published_at:datetime:index

Run Migration to Database

  1. $ rails db:migrate

Usage

Model

  1. include Publishing

Controller Params

  1. params.require(:model).permit(:published, :published_at)

Queries

  1. # All Models where published: true
  2. Model.is_published
  3. # All Models where published: false
  4. Model.is_unpublished

Ordering

  1. # published_at: :asc
  2. Model.is_published.published_asc
  3. # published_at: :desc
  4. Model.is_published.published_desc

Controller Action

  1. def publish
  2. @model = Model.find(params[:id])
  3. @model.publish_toggle
  4. # Response
  5. end

View

  1. = link_to @model.publish_link, model_publish_path(@model), method: :put

Routes

  1. put '/model/:id/publish' => 'model#publish'
  1. put '/model/:id/publish', to: 'model#publish'
  1. put '/model/:id/publish', to: :publish, controller: 'models'