Sha256: c3be85a3b657ce68b3e8c14a5d296fcd4d3522a8e4a63a0f9ce3f7ee588fa1ff
Contents?: true
Size: 898 Bytes
Versions: 3
Compression:
Stored size: 898 Bytes
Contents
module SimpleAdmin class EntitiesController < BaseController before_action :load_models def index models = [] ApplicationRecord.descendants.each do |model| models << { name: model.name, columns: model.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } } } end render json: { models: models } end def show resource_klass = params[:id].capitalize.constantize render json: { name: resource_klass.name, column_names: resource_klass.column_names, columns: resource_klass.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } }, reflections: resource_klass.reflections.keys } end private def load_models Rails.application.eager_load! end end end
Version data entries
3 entries across 3 versions & 1 rubygems