Sha256: 879ee49f26976df0097fb2576d62ff401d7d4ae4d9c76d033e356398f6e7f44f

Contents?: true

Size: 1013 Bytes

Versions: 3

Compression:

Stored size: 1013 Bytes

Contents

# <%= class_name %> Model
<% module_namespacing do -%>
class <%= class_name %> < ApplicationRecord
  include ActivityHistory
  include CloneRecord
  require 'csv'
  <%- attributes_names.each do |attribute| -%>
    <%- if @attachments.include?(attribute) -%>
  mount_uploader :<%=attribute%>, AttachmentUploader
    <%- end -%>
  <%- end -%>
  acts_as_list
  # Fields for the search form in the navbar
  def self.search_field
    fields = <%= attributes_names.map { |name| name } %>
    build_query(fields, :or, :cont)
  end

  def self.import(file)
    CSV.foreach(file.path, headers: true) do |row|
      begin
        self.create! row.to_hash
      rescue => err
      end
    end
  end

  def self.sorter(params)
    params.each_with_index do |id, idx|
      self.find(id).update(position: idx.to_i+1)
    end
  end

  # Funcion para armar el query de ransack
  def self.build_query(fields, operator, conf)
    query = fields.join("_#{operator}_")
    query << "_#{conf}"
    query.to_sym
  end
end
<% end -%>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
keppler-2.0.2 installer/core/lib/generators/keppler_scaffold/templates/models/model.rb
keppler-2.0.1 installer/core/lib/generators/keppler_scaffold/templates/models/model.rb
keppler-2.0.0 installer/core/lib/generators/keppler_scaffold/templates/models/model.rb