active_element

0.0.13
Light Mode Dark Mode

Setup

Installation

Install the active_element gem by adding the following to your Gemfile:

gem 'active_element'

Then rebuild your bundle:

$ bundle install

Application Controller

Inherit from ActiveElement::ApplicationController in the controller you want to use with ActiveElement. In most cases this will either be your main ApplicationController, or a namespaced admin area controller, e.g. Admin::ApplicationController. This will apply the default ActiveElement layout which includes a Navbar, Theme Switcher, and all the required CSS and Javascript.

If you want to add custom content to the layout, see the Hooks documentation, or if you want to use a completely custom layout, simply specify layout 'my_layout' in your ApplicationController.

# app/controllers/application_controller.rb

class ApplicationController < ActiveElement::ApplicationController
  # ...
end

Default Controller Actions

ActiveElement provides default controller actions for all controllers that inherit from ActiveElement::ApplicationController (directly or indirectly).

Each action provides boilerplate functionality to get your application off the ground as quickly as possible. See the Default Controller for full details.

The below example creates a /users endpoint for your application with boilerplate to list, search, view, create, edit, and delete users:

# config/routes.rb

Rails.application.routes.draw do
  resources :users
end
# app/controllers/users_controller.rb

class UsersController < ApplicationController
  active_element.listable_fields :name, :email, :created_at, order: :name
  active_element.viewable_fields :name, :email, :created_at, :updated_at
  active_element.editable_fields :name, :email
  active_element.searchable_fields :name, :name, :created_at, :updated_at
  active_element.deletable
end
# app/models/user.rb

class User < ApplicationRecord
end

You can now browse to /users on your local development server and see all the default behaviour provided by ActiveElement.

See the Default Controller and Custom Controllers sections for more details.


Documentation generated by rspec-documentation