Skip to content

Grupo-AFAL/blogging

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published