This commit is contained in:
15
app/models/book.rb
Normal file
15
app/models/book.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Book < ApplicationRecord
|
||||
include Accessable, Sluggable
|
||||
|
||||
has_many :leaves, dependent: :destroy
|
||||
has_one_attached :cover, dependent: :purge_later
|
||||
|
||||
scope :ordered, -> { order(:title) }
|
||||
scope :published, -> { where(published: true) }
|
||||
|
||||
enum :theme, %w[ black blue green magenta orange violet white ].index_by(&:itself), suffix: true, default: :blue
|
||||
|
||||
def press(leafable, leaf_params)
|
||||
leaves.create! leaf_params.merge(leafable: leafable)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user