Leolay Generators
A layout and customized scaffold generator for Rails to combine with active admin gem It generates the layout, the style, the internationalization and it helps you to startup active_admin gems
Compatibility
This version has been tested on:
- Rails
3.2.xand Ruby1.9.3on Windows OS - Rails
3.2.xand Ruby2.0.xon Windows OS - Rails
4.0.xand Ruby1.9.xon Windows OS - Rails
4.0.xand Ruby2.0.xon Windows OS - Rails
3.2.xand Ruby1.9.3on Linux - Rails
3.2.xand Ruby2.0.xon Linux - Rails
3.2.xand Ruby2.1.xon Linux - Rails
4.0.xand Ruby1.9.3on Linux - Rails
4.0.xand Ruby2.0.xon Linux - Rails
4.0.xand Ruby2.1.xon Linux
We are pleased to have achieved this result :smile:
Install
gem install active_leonardo
or
rails new ActiveLeo -m http://dl.dropbox.com/u/52600966/active_template.rb
Click here to download the template.
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 type:
rails generate leolay || rails destroy leolay
rails generate leosca || rails destroy leosca
You can run it more times and right like scaffold, it's smart and won't generate tons of identical code (thanks thor)
Warning: Leosca destroy do not remove variables parts inserted into feed like time values.
Step by step
Firstly, create layout and initialize your project:
rails new ActiveLeo -m http://dl.dropbox.com/u/52600966/active_template.rb(You can also find the template into gem root folder)
Answer y to all gems you need. After the questions it will start generations. If it is the first generation there will be a conflict on locales/en.yml, type y to overwrite.
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
You will get an application ready to work, run:
rails sand try it on http://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 into user model or you have to remove registerable code from
app\views\application\_session.html.erbYou can login as three different profiles loaded with a previous db:seed:
- [email protected], password: abcd1234 [this profile can do everything]
- [email protected], password: abcd1234 [can read, create and update]
- [email protected], password: abcd1234 [can read, create, update and destroy]
Create your resource:
rails g leosca product name:string description:text active:boolean items:integer price:decimalThis 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
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
You could also customize leonardo templates both views and controller. To copy under your project folder run:
rails g leosca:install
Then go to
lib\generators\erb
to edit erb views like you would do with original scaffold. Go to
lib\generators\rails
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-
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
Of course, these options are in addition to those provided by the original scaffold
Available layout
Currently the only one available is provided by ActiveAdmin
- active [default]
How to perform tests
Check current tasks typing:
bundle exec rake -T
rake active:tests:all[inspection] # Tests all rails versions
rake active:tests:newapp[inspection,rails] # Creates a test rails app for ...
rake active:tests:prepare[rails,path] # Prepare the environment passi...
if you want to test all, you can entrust to our package:
bundle exec rake active:tests:all[inspection]
if you pass the argument inspection you can check the application under the test folder:
test/TestApp_xxx_32
test/TestApp_xxx_40
where xxx is the current ruby version and the last number the rails version.
Every rails version has its own bundle under mybundle_xx folder.
If you want to perform a custom test, firstly make sure Gemfile.lock is not present otherwise delete it then you can type:
bundle exec active:tests:prepare['3.2','mybundle_path']
It sets the variable ENV[RAILS_CI] and prepares the package in the specified path
bundle exec rake active:tests:newapp[inspection]
the rails version has already been set by "active:tests:prepare" task.
If you execute tests with the inspection parameter remember to delete app folder under test/ before perform a new execution.
Tutorial
On my Blog you can find some other info.
Found a bug?
If you are having a problem please submit an issue at
Rails 3.2.x
Use previous 0.1.0 version (tested with activeadmin 0.5.x)
Rails 2 and Rails 3.0.x
This Generators does not work with versions earlier 3.1