This commit is contained in:
2025-11-07 13:34:32 -08:00
commit 1e8c5a972b
436 changed files with 11000 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
module SetBookLeaf
extend ActiveSupport::Concern
included do
before_action :set_book
before_action :set_leaf, :set_leafable, only: %i[ show edit update destroy ]
end
private
def set_book
@book = Book.accessable_or_published.find(params[:book_id])
end
def set_leaf
@leaf = @book.leaves.active.find(params[:id])
end
def set_leafable
instance_variable_set "@#{instance_name}", @leaf.leafable
end
def ensure_editable
head :forbidden unless @book.editable?
end
def model_class
controller_leafable_name.constantize
end
def instance_name
controller_leafable_name.underscore
end
def controller_leafable_name
self.class.to_s.remove("Controller").demodulize.singularize
end
end