Skip to content

getsimpleadmin/simpleadmin-ruby

Repository files navigation

Build Status codecov.ioGem Version

SimpleAdmin provides builder for administrative dashboards, it's fit for Web / Mobile / API. Cloud or your own servers, depends on your choice and requirements.

All common admin dashboard tasks like content create / update / delete operations, charts, invite colleagues.

This is API Rack Application to connect your application with SimpleAdmin service.

Example Application

Requirements

  • Ruby ~> 2.3

Installation

simple_admin

Add SimpleAdmin to your application's Gemfile:

gem 'simpleadmin'

And then run:

bundle install

Configuration in Ruby on Rails

Just run next command:

rails generate simpleadmin:install

It will automatically add initializer and SimpleAdmin API routes. Default secret key for your application:

SECRET_KEY

Don't forget to change it in production

Configuration in Hanami, Sinatra and etc.

Add the next line to your routes file to mount simpleadmin built-in routes:

# config/routes.rb
Rails.application.routes.draw do
  mount Simpleadmin::Application, at: 'simpleadmin'
end

Create initializer, add your secret key and restart server

# config/initializers/simpleadmin.rb
ENV['SIMPLE_ADMIN_SECRET_KEY'] = 'SECRET_KEY'

Simpleadmin::Config.setup do |config|
    #  For Ruby on Rails, you don't need to define database credentials directly, 
    #  also when you deployed it on Heroku. In other cases define database 
    #  credentials using the syntax below
    config.database_credentials = {
       adapter: :postgres,
       database: 'demo_development'
    }
    
    # By default all tables permitted, but you can select what tables you want to use in the admin panel
    config.allowed_tables = ['users', 'orders']
   
    #  DSL to describe CRUD actions in an application. In Ruby on Rails, you don't need to define it 
    config.on_create = lambda do |model_class, resource_params|
      model_class.create(resource_params)
    end

    config.on_update = lambda do |model_class, resource_id, resource_params|
      model_class.find(resource_id).update(resource_params)
    end

    config.on_destroy = lambda do |model_class, resource_id|
      model_class.find(resource_id).destroy
    end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/getsimpleadmin/simpleadmin.

License

The gem is available as open source under the terms of the MIT License.

About

Create admin dashboards for Web / Mobile / API applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published