Coder Social home page Coder Social logo

puffer's Introduction

Build Status

Achtung!

It's better to install Puffer from the HEAD of ruby repo now.

gem "puffer", :git => "git://github.com/puffer/puffer.git"

Puffer โ€” YARAI (Yet Another Rails Admin Interface)

Puffer was created to help a project owner or moderators view and edit all the project's data models.

It's compatible with Rails >= 3.1 only.

Discussion and help

xmpp:[email protected]

Key features

  • Full Ruby on Rails integration. Puffer has no configuration files, but a DSL to define administration interfaces. This DSL follows the Rails conventions.
  • Flexibility. Puffer designed to provide much flexibility as possible, so you can create your own extensions without any design issues.
  • Internationalization. Surely, enjoy the native Rails i18n subsystem.
  • Puffer supports different ORMs or ODMs through the orm_adapter gem. Currently, we can work with ActiveRecord and Mongoid.

Installation.

You can install puffer as a gem:

gem install puffer

Or in Gemfile:

gem "puffer"

Post-installation actions.

First of all, it is nessesary to create security system for admin interface. It consists of two parts: user model and sessions controller. There are two cases for it:

Integrated auth system

Simple integarted auth system. To activate it - just execute rails g puffer:puffer_user. This will create model, migrations, controller and routes for PufferUser model. Also, default sessions controller which uses PufferUser model already in engine. So, both parts of auth system are ready for usage. Also there is mongoid backend for PufferUser storage. See generator usage for details.

External auth system

If application already use some kind of auth system like a devise, clearance or sorcery - you should use corresponding SessionsController backend. Just create app/controllers/admin/sessions_controller.rb in your application directory to redefine default SessionsController.

The content of file depends on used auth system. There are several backends for SessionsController exists in Puffer. I.e. for clearance use:

class Admin::SessionsController < Puffer::Sessions::Clearance
end

See https://github.com/puffer/puffer/tree/master/lib/puffer/backends/controllers/sessions for the list of backends. Also you can create your own backend.

If you use app's auth system, you might want to redefine access rules. The simpliest way for it - is to redefine current_puffer_use or has_puffer_access? methods in controller or implement has_role? method for your user model. See https://github.com/puffer/puffer/blob/master/lib/puffer/controller/auth.rb for details.

Introduction.

Let's assume this is the data structure of your application:

create_table "users", :force => true do |t|
  t.string   "email"
  t.string   "password"
  t.datetime "created_at"
  t.datetime "updated_at"
end

create_table "posts", :force => true do |t|
  t.integer  "user_id"
  t.string   "title"
  t.text     "body"
  t.datetime "created_at"
  t.datetime "updated_at"
end

And let's also assume your models look like this:

class User < ActiveRecord::Base
  has_many :posts
  validates_presence_of :email, :password
  validates_length_of :password, :minimum => 6
end

class Profile < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :name, :surname
end

First, let's generate the Puffer controllers:

rails g puffer:controller User

and

rails g puffer:controller Post

This will generate the following code:

class Admin::PostsController < Puffer::Base
  setup do
    group :posts
  end

  index do
    field :id
    field :user_id
    field :title
    field :body
    field :created_at
    field :updated_at
  end

  form do
    field :id
    field :user_id
    field :title
    field :body
    field :created_at
    field :updated_at
  end

end

Puffer's DSL creates all the actions you need. Next step is routing.

namespace :admin do
  resources :users do
    resources :posts
  end
  resources :posts
end

Let me explain this feature. Puffer tracks all the nested resources. For instance, according to our routing definitions, we can access only specified posts of our user:

/admin/users/1/post

Routing nesting implies the admin resources nesting.

Advanced usage

Puffer can work in different namespaces:

rails g puffer:controller moderator/posts

And we'll get posts controller for moderators:

class Moderator::PostsController < Puffer::Base
  before_filter :require_moderator

  setup do
    destroy false
    group :posting
  end

  index do
    field :user_id
    field :title
    field :body
  end

  form do
    field :user_id
    field :title
    field :body
    field :created_at
    field :updated_at
  end
end

As you can see, moderators can't destroy posts. The moderator's post controller is placed in the Posting tab of the admin interface.

Finally, don't forget about routing:

namespace :moderator do
  resources :posts
end

Have a nice day and let Puffer rock for you.


Thanks to Dmitry Ustalov for the name of Puffer along with the Clearance integration.

puffer's People

Contributors

abonec avatar alexrothenberg avatar andrewgr avatar cs3b avatar dustalov avatar iltempo avatar mdorfin avatar olivierlacan avatar pyromaniac avatar rakoth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.