add folders structure

This commit is contained in:
Alex Turchyn
2023-09-22 02:20:38 +03:00
parent f8712a9da9
commit 380f553a17
30 changed files with 405 additions and 56 deletions
+1
View File
@@ -34,6 +34,7 @@ module Accounts
new_template = Template.find(1).dup
new_template.account_id = account.id
new_template.slug = SecureRandom.base58(14)
new_template.folder = account.default_template_folder
new_template.save!
+17
View File
@@ -0,0 +1,17 @@
# frozen_string_literal: true
module TemplateFolders
module_function
def search(folders, keyword)
return folders if keyword.blank?
folders.where(TemplateFolder.arel_table[:name].lower.matches("%#{keyword.downcase}%"))
end
def find_or_create_by_name(author, name)
return author.account.default_template_folder if name.blank? || name == TemplateFolder::DEFAULT_NAME
author.account.template_folders.create_with(author:, account: author.account).find_or_create_by(name:)
end
end