add folders structure
This commit is contained in:
@@ -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!
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user