app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.7 vs app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.8

- old
+ new

@@ -12,7 +12,31 @@ end end link_to r.send(field), send(path, args) end end + + def self.auto_datatable(klazz, link_path: nil, only: []) + collection do + klazz.all + end + + datatable do + bulk_actions_col + klazz.new.attributes.each do |att| + key = att[0] + next if only.size.positive? && !only.include?(key) + sym = key.gsub('_id', '').to_sym + visible = !['created', 'updated', 'created_at', 'updated_at', 'deleted_at', 'current_user', 'current_action'].include?(key) + if link_path.present? && sym == :id + link_col sym, link_path, :id + elsif link_path.present? && sym == :name + link_col sym, link_path, [:id, :name] + else + col sym, visible: visible + end + end + actions_col + end + end end end