ActiveAdmin – An administration framework for Ruby on Rails – The Problem



ActiveAdmin – An administration framework for Ruby on Rails – The Problem

0 0


activeadmin-presentation

Presentation about ActiveAdmin for Burlington Ruby.

On Github tristanoneil / activeadmin-presentation

ActiveAdmin

An administration framework for Ruby on Rails

The Problem

class PostsController < ApplicationController
  def update
    @post = Post.find(params[:id])
    @post.update_attributes(params[:post])
  end
end

class PagesController < ApplicationController
  def update
    @page = Page.find(params[:id])
    @page.update_attributes(params[:page])
  end
end

The Problem

  <%= form_for(@post) do |f| %>
    <%= f.text_field :title %>
    <%= f.text_area :body %>

    <%= f.submit %>
  <% end %>

  <%= form_for(@page) do |f| %>
    <%= f.text_field :title %>
    <%= f.text_area :body %>

    <%= f.submit %>
  <% end %>

The Solution

ActiveAdmin.register Post do
end

ActiveAdmin.register Page do
end

It's Pretty

Get Started

Add to Gemfile

gem 'activeadmin'

Run in CLI

rails generate active_admin:install
rails generate active_admin:resource [resource]

Domain Specific Language

Index Views

index do
  column :title
  column :author
  default_actions
end

index do
  column :title
  if can? :manage, Post
    column :some_secret_data
  end
end

Show Views

show do
  h3 post.title
  div do
    markdown post.body
  end

  panel "Comments" do
    table_for(workshop.comments) do
      column :name
      column :email
    end
  end
end

Form Definitions

form do |f|
  f.inputs "Post Details" do
    f.input :title
    f.input :author, :as => :select, :collection => ["Tristan O'Neil"]
    f.input :created_at, :ampm => true
    f.input :body
  end

  f.buttons
end

Controller Definitions

controller do
  def update
    # override default update action behavior.
  end
end

Demo Time