I am going to create a quick-start demo which would be helpful to  guide how to get an application set up with HAML.

App setup:

Rails 3.1, Mongodb,haml

1. rails new test_haml --skip active-record

will create a new app “test_haml” and skip active record libraries since i am using Mondodb so i will use mongoid.

2.Include some gems in gemfile.

gem ‘mongoid’, ‘2.0.0.beta.19’
gem ‘bson_ext’
gem “haml”

3. Now our’s next command will be

bundle install

because we need to update app with latest gem added in gemfile. Once the gems have installed we’ll need to run the Mongoid configuration generator so that it can create the configuration YAML file.

4.rails g mongoid:config

that will generate file mongoid.yaml some like
efaults: &defaults
host: localhost
# slaves:
#   – host: slave1.local
#     port: 27018
#   – host: slave2.local
#     port: 27019development:
<<: *defaults
database: test_haml_developmenttest:
<<: *defaults
database: test_haml_test

# set these environment variables on your prod server
host: <%= ENV[‘MONGOID_HOST’] %>
port: <%= ENV[‘MONGOID_PORT’] %>
username: <%= ENV[‘MONGOID_USERNAME’] %>
password: <%= ENV[‘MONGOID_PASSWORD’] %>
database: <%= ENV[‘MONGOID_DATABASE’] %>

5.git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

This will configure Rails 3 to use HAML generators instead of ERB  when we run any sacffold or controller because it is annoying to constantly remove .erb files, and or edit them into HAML syntax.

6. Finally we have need a small configuration setup that will assist in haml file generation.

we will add this bit of code in config/application.rb after "config.filter_parameteres +=[:password]" 
config.generators do |g|   g.template_engine :haml  end We completed with all setup, now need to run a sacffold and let's see how is working!!!!!!!!!!!!!!!!! 

7.rails generate scaffold Contacts name:string phone:string

8. rais server

take a look in view folder, you find all file in haml extention.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s