View the Project on GitHub codn/adminpanel

Special Behavior



Behavior · Adminpanel

def self.form_attributes

This method is going to be used to generate the form and display the fields in the panel, it must return an array of hashes:

def self.form_fields
    'name' => {
      'type' => 'text_field',
      'label' => 'Nickname',
      'placeholder' => 'John Doe',
      'show' => 'index'

in the example above, 'name' is the database field, 'type' is the form type, 'show' is an extra attribute described below and label and placeholder are that.

types supported

additional keys and values supported

def self.routes_options

This method should return a hash with params for the resources method in the routes, for example, this can be used to don’t show some links or to change the path of the resource.

{ except:[:destroy, :new], path:'super-resource' }

def self.member_routes

This methods insert routes inside a member when generating the routes, for restful custom routes.

  'put' => {
    'path' => :some_controller_method,
    'args' => { as: 'super_action', path: 'super-path' }
  'post' => {
    'path' => :other_controller_method,
    'args' => { as: 'move' }

Adminpanel is going to insert those routes into:

resources :model do
  member do
    put :some_controller_methods, { as: 'super_action', path: 'super-path' }
    post :other_controller_method, { as: 'move' }

After this, you’ll only need to:

def self.collection_routes

See member routes, and change for collection

def self.collection_name

This method returns the string that is going to be shown in the side menu, routes and breadcrumb, by default use the pluraliztion of self.display_name