Admin Helper Reference

Helper methods available in RailsPress admin views for consistent styling and behavior.

Form Field Helpers

These helpers render form fields with consistent styling and labels.

rp_string_field

Single-line text input for strings.

ERB
<%= rp_string_field form, :title %>
<%= rp_string_field form, :title, autofocus: true %>
<%= rp_string_field form, :email, placeholder: "user@example.com" %>

rp_text_field

Multi-line textarea for longer text.

ERB
<%= rp_text_field form, :description %>
<%= rp_text_field form, :description, rows: 6 %>

rp_rich_text_field

Rich text editor (ActionText) for formatted content.

ERB
<%= rp_rich_text_field form, :content %>
<%= rp_rich_text_field form, :body %>

rp_boolean_field

Checkbox for boolean values.

ERB
<%= rp_boolean_field form, :published %>
<%= rp_boolean_field form, :featured %>

rp_datetime_field

Datetime picker input.

ERB
<%= rp_datetime_field form, :published_at %>

rp_select_field

Dropdown select input.

ERB
<%= rp_select_field form, :status, choices: %w[draft published] %>
<%= rp_select_field form, :category_id, choices: Category.all.map { |c| [c.name, c.id] } %>

rp_attachment_field

File upload with preview and removal checkbox.

ERB
<%= rp_attachment_field form, :header_image, record: @post %>

<%# For multiple attachments %>
<%= rp_attachment_field form, :gallery, record: @project, multiple: true %>

rp_list_field

Text input for comma-separated lists.

ERB
<%= rp_list_field form, :tech_stack %>
<%# Renders with hint: "Separate items with commas" %>

Layout Helpers

Helpers for consistent page structure and UI components.

rp_page_header

Page title with optional action buttons.

ERB
<%= rp_page_header "Posts" %>

<%= rp_page_header "Posts", actions: {
  "New Post" => new_admin_post_path
} %>

rp_card

Card container with optional title.

ERB
<%= rp_card do %>
  <p>Card content here</p>
<% end %>

<%= rp_card title: "Statistics" do %>
  <p>Dashboard stats</p>
<% end %>

rp_sidebar_section

Groups related form fields in the sidebar.

ERB
<%= rp_sidebar_section "Publishing" do %>
  <%= rp_select_field form, :status, choices: %w[draft published] %>
  <%= rp_datetime_field form, :published_at %>
<% end %>

rp_empty_state

Empty state message with optional action link.

ERB
<%= rp_empty_state "No posts yet" %>

<%= rp_empty_state "No posts yet",
    link_text: "Create your first post",
    link_path: new_admin_post_path %>

Display Helpers

Helpers for formatting data in tables and detail views.

rp_status_badge

Colored badge for status values.

ERB
<%= rp_status_badge "published", type: :success %>
<%= rp_status_badge "draft", type: :warning %>
<%= rp_status_badge "archived", type: :neutral %>
<%= rp_status_badge "deleted", type: :danger %>

Types: :success, :warning, :danger, :neutral, :info

rp_boolean_badge

Yes/No badge for boolean values.

ERB
<%= rp_boolean_badge(post.featured?) %>
<%# Output: "Yes" (green) or "No" (gray) %>

<%= rp_boolean_badge(post.published?, true_text: "Published", false_text: "Draft") %>

rp_datetime_display

Formats datetime for display.

ERB
<%= rp_datetime_display(post.published_at) %>
<%# Output: "Jan 15, 2025 at 3:30 PM" %>

<%= rp_datetime_display(post.created_at, format: :short) %>
<%# Output: "Jan 15" %>

rp_truncated_text

Truncates long text with ellipsis.

ERB
<%= rp_truncated_text(post.title) %>
<%# Truncates at 50 chars by default %>

<%= rp_truncated_text(post.content.to_plain_text, length: 100) %>

Button Helpers

rp_button

Styled button or button-style link.

ERB
<%= rp_button "Save", type: :submit %>
<%= rp_button "Cancel", path: admin_posts_path, variant: :secondary %>
<%= rp_button "Delete", path: admin_post_path(@post), variant: :danger, method: :delete, confirm: "Are you sure?" %>

Variants: :primary, :secondary, :danger, :ghost

rp_button_group

Groups multiple buttons together.

ERB
<%= rp_button_group do %>
  <%= rp_button "Save", type: :submit %>
  <%= rp_button "Cancel", path: admin_posts_path, variant: :secondary %>
<% end %>

Complete Example

Here's a complete example using these helpers in a custom entity form:

app/views/railspress/admin/entities/_form.html.erb
<%= form_with model: @record, url: form_url, class: "rp-form" do |f| %>
  <%= rp_form_errors(@record) %>

  <div class="rp-form__layout">
    <div class="rp-form__main">
      <%= rp_string_field f, :title, autofocus: true %>
      <%= rp_text_field f, :description, rows: 4 %>
      <%= rp_rich_text_field f, :body %>
    </div>

    <div class="rp-form__sidebar">
      <%= rp_sidebar_section "Status" do %>
        <%= rp_boolean_field f, :published %>
        <%= rp_datetime_field f, :published_at %>
      <% end %>

      <%= rp_sidebar_section "Image" do %>
        <%= rp_attachment_field f, :cover_image, record: @record %>
      <% end %>
    </div>
  </div>

  <div class="rp-form__actions">
    <%= rp_button "Save", type: :submit %>
    <%= rp_button "Cancel", path: entity_index_path, variant: :secondary %>
  </div>
<% end %>

CSS Classes Reference

All RailsPress components use the rp- prefix:

Class Element
.rp-form Form container
.rp-form__layout Two-column form layout
.rp-form__main Main content column
.rp-form__sidebar Sidebar column
.rp-card Card container
.rp-btn Button base
.rp-btn--primary Primary button
.rp-table Table container
.rp-badge Status badge

See Theming for CSS customization options.