module ViewComponent::PreviewActions
def find_preview
def find_preview candidates = [] params[:path].to_s.scan(%r{/|$}) { candidates << Regexp.last_match.pre_match } preview = candidates.sort_by(&:length).reverse_each.detect { |candidate| ViewComponent::Preview.exists?(candidate) } if preview @preview = ViewComponent::Preview.find(preview) else raise AbstractController::ActionNotFound, "Component preview '#{params[:path]}' not found." end end