Configuration
Configure authors, post images, authentication, and other RailsPress options.
Basic Setup
Create an initializer at 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.
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.
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.
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.
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.
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.).
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.
# 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.
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)
Railspress.configure do |config|
config.enable_post_images
end
With Devise Authentication
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
class User < ApplicationRecord
scope :writers, -> { where(role: %w[writer editor admin]) }
def display_name
"#{first_name} #{last_name}"
end
end
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:
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:
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