russian-book-story/app/models/story_page.rb
viktorvsk f3d33199f0
Some checks failed
CI / Lint & Test (push) Has been cancelled
Deploy Status Page / Build & Deploy (push) Has been cancelled
Волшебная Книга: Russian book storytelling app
- Book-styled UI with parchment aesthetic and Russian navigation
- Characters model with Konva.js 2D canvas drawing (draggable shapes)
- StoryPages model with character association and page navigation
- Stimulus controllers: canvas (editor) + canvas-preview (read-only)
- Full Russian interface: all labels, buttons, flash messages in Russian
2026-04-25 15:29:15 +00:00

19 lines
462 B
Ruby

# frozen_string_literal: true
class StoryPage < ApplicationRecord
belongs_to :character, optional: true
validates :content, length: { maximum: 5000 }
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
default_scope { order(:position, :created_at) }
before_create :assign_position
private
def assign_position
self.position = (StoryPage.unscoped.maximum(:position) || -1) + 1 if position.zero?
end
end