Blogging will help you easily add blog functionality to your Rails application.
- Install
vips
(https://www.libvips.org/install.html) ActionText
must be configured (https://edgeguides.rubyonrails.org/action_text_overview.html)Mobility
(https://github.com/shioyama/mobility)Friendly Id
(https://github.com/norman/friendly_id/)Friendly Id mobility
(https://github.com/shioyama/friendly_id-mobility)- A
Post
belongs to anauthor
. So, host application must provide a model to use as anauthor
. Default model isUser
.
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'
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
- 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
The gem is available as open source under the terms of the MIT License.