Leolay Generators

A layout and customized scaffold generator for Rails 3 to combine with active admin gem It generates the layout, the style, the internationalization and it helps you to startup active_admin gems

Install

gem install active_leonardo

or

rails new ActiveLeo -m http://dl.dropbox.com/u/52600966/active_template.rb

Usage

Once you install the gem, the generators will be available to all Rails applications on your system.

To run the generator, go to your rails project directory and call it using rails generate or destroy command: rails generate leolay or rails destroy leolay rails generate leosca or rails destroy leosca

PS: leosca destroy do not remove variables parts like time values inserted into feed

PPS: You can run it more times and right like scaffold, it’s smart and won’t generate tons of identical code (thanks thor)

Step by step

  1. Firstly, create layout and initialize your project:

rails new ActiveLeo -m dl.dropbox.com/u/52600966/active_template.rb (You can also find a template into gem root folder)

Answer y to all gems you need. After the questions will start generations. There will be a conflict on locales/en.yml which you must force if it is the first generation.

Will be:

  • Created a default layout like active admin

  • Created i18n files

  • Created user management on active admin

  • Customized application.rb to exclude javascript and stylesheet for every resource you will create

  1. You will get an application ready to work:

run rails s and try it on localhost:3000

if you get this message: _undefined local variable or method ‘new_user_registration_path’_ **be sure user model have :registerable devise’s module** otherwise add it or you have to remove registerable code from appviewsapplication_session.html.erb you also may have to restart server: Ctrl+C and rails s once again

now go into admin section: run rails s and try it on localhost:3000/admin

You can login as three different profiles loaded with a previous db:seed:

email: [email protected], password: abcd1234
[this profile can do everything]
or
email: [email protected], password: abcd1234
[can read, create and update]
or
email: [email protected], password: abcd1234
[can read, create, update and destroy]
  1. Create your resource:

rails g leosca product name:string description:text active:boolean items:integer price:decimal

This will act as a normal scaffold and has more new features:

  • will be invoked new leosca_controller which is a customized scaffold_controller

  • attributes will be insert into i18n files for a quick translation

  • seeds will be created for you to populate new table

  • invoke active admin generator to add the new resource with a custom configuration to work with cancan

  1. Apply to db as always you do:

rake db:migrate rake db:seed

That’s all! The new application is ready to be customized to suit your needs:

* start to develop user front end
* take advantage of active admin and its dsl to quickly setup administration section

If you get this message: __Can’t mass-assign protected attributes: foo_id, bar_id__ just add it to attr_accessible inside your model

**If you login with admin profile you can also manage users**, you only have to add :roles to attr_accessible inside user’s model

You could also customize leonardo templates: both views and controller. To copy under your project folder run: rails g leosca:install

Then go to libgeneratorserb to edit erb views like you would do with original scaffold. Go to libgeneratorsrails if you want to customize more.

For more information about usage:

rails g leolay --help

rails g leosca --help

Example:

leolay:

rails generate leolay
rails generate leolay --skip-authentication --skip-authorization

leosca:

rails generate leosca product name:string
rails generate leosca product name:string --skip-seeds
rails generate leosca product name:string --seeds=60          => if you need more records

if you made a mistake and want to start from scratch just replace generate with destroy to remove all files and inserted code

PS: Of course, these options are in addition to those provided by the original scaffold

Available layout

* active [default]

Tutorial

That what do you think is??? :)

Found a bug?

If you are having a problem please submit an issue at [email protected]

Rails 2 and Rails 3.0.x

This Generators does not work with versions earlier 3.1