Configuration

Configure authors, post images, authentication, and other RailsPress options.

Basic Setup

Create an initializer at config/initializers/railspress.rb:

config/initializers/railspress.rb
Railspress.configure do |config|
  # Configuration options go here
end

Feature Toggles

enable_authors

Enables author/user association for posts. When enabled, posts can be assigned to authors and the author dropdown appears in the post form.

Ruby
Railspress.configure do |config|
  config.enable_authors
end

Default: Disabled

enable_post_images

Enables post image uploads for posts. When enabled, posts can have a featured/header image attached via Active Storage.

Ruby
Railspress.configure do |config|
  config.enable_post_images
end

Default: Disabled

enable_focal_points

Enables focal point selection for header images. When enabled, editors can set the focal point (important area) of images to control cropping across different aspect ratios.

Ruby
Railspress.configure do |config|
  config.enable_post_images    # Required first
  config.enable_focal_points   # Then enable focal points
end

Default: Disabled

Requirements: Must also enable enable_post_images. Requires running migrations for the railspress_focal_points table.

See Image Focal Point System for full documentation including image contexts, per-context overrides, and view helpers.

enable_cms

Enables Blocks -- the copy and images on your site itself (headlines, blurbs, CTAs, hero images). When enabled, you get Content Groups and Content Elements models, admin UI sidebar links, dashboard stats, the cms_element and cms_value view helpers, and the chainable Railspress::CMS API.

Ruby
Railspress.configure do |config|
  config.enable_cms
end

Default: Disabled

When CMS is disabled, calling cms_element or cms_value in a view raises Railspress::ConfigurationError. CMS routes are not mounted and CMS links do not appear in the admin sidebar.

Inline editing builds on top of CMS. See Inline Editing for how to enable right-click editing of CMS content on public pages.

blog_path

The public URL path where your blog posts are displayed on your site. Used to generate "View" links in the admin interface that link to the live post on your frontend.

Ruby
config.blog_path = "/blog"       # default
config.blog_path = "/articles"   # custom path
config.blog_path = "/news"       # news section

Default: "/blog"

The admin post show page displays a "View" button for published posts that links to #{blog_path}/#{post.slug}.

words_per_minute

Words per minute used for calculating estimated reading time on posts.

Ruby
config.words_per_minute = 200    # default
config.words_per_minute = 250    # faster readers
config.words_per_minute = 150    # more technical content

Default: 200

inline_editing_check

A proc that determines whether inline editing controls are shown to the current user. Receives the view helper context.

Ruby
config.inline_editing_check = ->(context) {
  context.controller.current_user&.admin?
}

Default: nil (inline editing disabled)

Requires: enable_cms must be set. Without it, setting this option raises Railspress::ConfigurationError.

Accessing Configuration Programmatically

Ruby
Railspress.authors_enabled?        # => true/false
Railspress.post_images_enabled?    # => true/false
Railspress.focal_points_enabled?   # => true/false
Railspress.cms_enabled?            # => true/false
Railspress.author_class            # => User (the actual class)
Railspress.available_authors       # => ActiveRecord::Relation
Railspress.author_display_method   # => :name
Railspress.current_author_method   # => :current_user
Railspress.blog_path               # => "/blog"
Railspress.words_per_minute        # => 200

Author Configuration

These options are only relevant when enable_authors is called.

author_class_name

The class name of your user/author model as a string.

Ruby
config.author_class_name = "User"        # default
config.author_class_name = "Admin"       # custom model
config.author_class_name = "Author"      # dedicated author model

current_author_method

The controller method that returns the currently signed-in user. This integrates with your authentication system (Devise, Clearance, custom auth, etc.).

Ruby
config.current_author_method = :current_user   # default (Devise)
config.current_author_method = :current_admin  # admin-specific
config.current_author_method = :logged_in_user # custom auth

author_scope

Limits which users appear in the author dropdown. Accepts a Symbol (scope name) or a Proc.

Ruby
# Use a scope defined on the User model
config.author_scope = :authors           # calls User.authors
config.author_scope = :active            # calls User.active

# Use a Proc for complex logic
config.author_scope = ->(klass) { klass.where(role: "writer") }

author_display_method

The method called on author objects to display their name in dropdowns and post listings.

Ruby
config.author_display_method = :name       # default
config.author_display_method = :full_name
config.author_display_method = :email
config.author_display_method = :display_name

Example Configurations

Minimal Setup (No Authors)

config/initializers/railspress.rb
Railspress.configure do |config|
  config.enable_post_images
end

With Devise Authentication

config/initializers/railspress.rb
Railspress.configure do |config|
  config.enable_authors
  config.enable_post_images
  config.author_class_name = "User"
  config.current_author_method = :current_user
  config.author_display_method = :email
end

With Scoped Authors

app/models/user.rb
class User < ApplicationRecord
  scope :writers, -> { where(role: %w[writer editor admin]) }

  def display_name
    "#{first_name} #{last_name}"
  end
end
config/initializers/railspress.rb
Railspress.configure do |config|
  config.enable_authors
  config.author_class_name = "User"
  config.author_scope = :writers
  config.author_display_method = :display_name
end

Adding Authentication

RailsPress does not include authentication. Protect the admin area by configuring your application controller:

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  # If using Devise
  before_action :authenticate_user!, if: :railspress_admin?

  private

  def railspress_admin?
    request.path.start_with?("/railspress/admin")
  end
end

Or override the RailsPress base controller:

config/initializers/railspress.rb
Rails.application.config.to_prepare do
  Railspress::Admin::BaseController.class_eval do
    before_action :authenticate_user!
    before_action :require_admin!

    private

    def require_admin!
      redirect_to root_path unless current_user&.admin?
    end
  end
end