Apr 05 2010

How to Install and Use Rails 3 Generators

Rails3 Ruby GettingThingsRight | comments

This is why Rails3's philosophy is agnosticism:

You can override default template engine (erb) through config/application.rb. So if you use HAML, running scaffold generator will create HAML files for the views. If you use Rspec for testing as most Ruby developers do, you may also specify rspec as the default test framework.

              #Configure generators values. Many other options are available, be sure to check the documentation.
              config.generators do |g|
                g.template_engine :haml
                g.test_framework :rspec, :fixture => true, :views => false
              end
              

I think the right repository for the Rails 3 generators is the one maintained by Andre Arko of Engine Yard.

              cd yourapp
              git clone git://github.com/indirect/rails3-generators.git lib/generators
              

Blog app basics:

              script/rails generate scaffold post title:string body:text published:boolean 
              

Update:

To install the Rails 3 generators. Add this on your Gemfile:

              gem 'rails3-generators'
              

This gem adds more generators for you.

              rails g 
              
              ActiveRecord:
                active_record:devise
              
              ActsAsTaggableOn:
                acts_as_taggable_on:migration
              
              Authlogic:
                authlogic:session
              
              Cucumber:
                cucumber:feature
                cucumber:install
              
              Devise:
                devise
                devise:install
                devise:views
              
              EmailSpec:
                email_spec:steps
              
              Formtastic:
                formtastic:form
                formtastic:install
              
              FriendlyId:
                friendly_id
              
              Jquery:
                jquery:install
              
              Koala:
                koala:install
              
              MongoMapper:
                mongo_mapper:install
              
              Mongoid:
                mongoid:devise
                mongoid:install
              
              Mustache:
                mustache:install
              
              Paperclip:
                paperclip
              
              Rspec:
                rspec:install
              
              

Without RSpec, you could just use the following:

              
              config.generators do |g|
                g.template_engine :haml
              end