lib/generators/breadko/templates/breadko_datatable.erb

Summary

Maintainability
Test Coverage
class <%= object.camelize %>Datatable < AjaxDatatablesRails::Base
  def_delegator :@view, :link_to
  def view_columns
    # Declare strings in this format: ModelName.column_name
    # or in aliased_join_table.column_name format
    @view_columns ||= {
   <% attributes.each do |attribute| -%>
    <%= attribute.name %>: { source: "<%= object.camelize %>.<%= attribute.name %>", cond: :like },
   <% end -%>
    actions: { source: "<%= object.camelize %>.id", cond: :like }
    }
  end

  def data
    records.map do |record|
      {
  <% attributes.each do |attribute| -%>
   <%= attribute.name %>: record.<%= attribute.name %>,
  <% end -%>
   actions: actions(record)
      }
    end
  end

  private

  def actions(_record)
    ""
  end

  def get_raw_records
    options[:current_account].<%= objects %>.active_status
  end

  # ==== These methods represent the basic operations to perform on records
  # and feel free to override them

  # def filter_records(records)
  # end

  # def sort_records(records)
  # end

  # def paginate_records(records)
  # end

  # ==== Insert 'presenter'-like methods below if necessary
end