Skip to content

Latest commit

 

History

History
136 lines (110 loc) · 2.53 KB

README.md

File metadata and controls

136 lines (110 loc) · 2.53 KB

Blogging

Blogging will help you easily add blog functionality to your Rails application.

Prerequisites

Installation

Add this line to your application's Gemfile:

gem "blogging"

And then execute:

$ bundle

Or install it yourself as:

$ gem install blogging

Generate migration files:

$ rails blogging:install:migrations

Run migrations:

$ rails db:migrate

Add this line to your applications's routes file (routes.rb):

mount Blogging::Engine => '/blog'

Blogging configuration

Add an initializer to your Rails application, i.e. config/initializers/blogging.rb

Blogging.config do |config|
  # Configure author model
  config.author_class = 'Person'
  config.authors = -> { Person.all }
  config.author_name = lambda { |author| author.name }

  # Configure parent controllers
  config.parent_controller = 'ApplicationController'
  config.parent_admin_controller = 'Admin::BaseController'

  # Configure public layout
  config.public_layout = 'blog'
end

Overwrite admin controllers permissions

  • Create app/policies/blogging/post_policy.rb
  • Then add your own rules:
module Blogging
  class PostPolicy < ApplicationPolicy
    def index?
      # Custom rule
    end

    def show?
      # Custom rule
    end

    def create?
      # Custom rule
    end

    def new?
      # Custom rule
    end

    def update?
      # Custom rule
    end

    def edit?
      # Custom rule
    end

    def destroy?
      # Custom rule
    end
  end
end
  • Create app/policies/blogging/tag_policy.rb
  • Then add your own rules:
module Blogging
  class PostPolicy < ApplicationPolicy
    def index?
      # Custom rule
    end

    def show?
      # Custom rule
    end

    def create?
      # Custom rule
    end

    def new?
      # Custom rule
    end

    def update?
      # Custom rule
    end

    def edit?
      # Custom rule
    end

    def destroy?
      # Custom rule
    end
  end
end

License

The gem is available as open source under the terms of the MIT License.