Saturday, February 21, 2009

How to: Deploy on Server

How to: Deploy on Server

How to: Creating New Gem in Ruby on Rails

How to: Creating New Gem in Ruby on Rails

Creating New Gem in Ruby on Rails

In the Past I have created gem for my plugin. Now I am sharing my approach that I have used to do it. Finally I feel how easy it is.

We can do it just add gem specifications within rake file (vendor\plugins\\rake).

Classes to be require

require 'rubygems'

require 'rake'

require 'rake/testtask'

require 'rake/rdoctask'

require 'rake/packagetask'

require 'rake/gempackagetask'

Define Specification

desc 'Default: run unit tests.'

task :default => :test

desc 'description of your gem' do |t|

t.libs << 'lib'

t.pattern = 'test/**/*_test.rb'

t.verbose = true


desc 'Generate documentation for your gem.' do |rdoc|

rdoc.rdoc_dir = 'rdoc'

rdoc.title = 'display title'

rdoc.options << '--line-numbers' << '--inline-source'




spec = do |s|

s.platform = Gem::Platform::RUBY

s.summary = "Ruby based make-like utility." = 'plugin_name'

s.version = '0.0.1'

s.requirements << 'none'

s.require_path = 'lib'

s.autorequire = 'plugin_name'

s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }

s.description = 'Test act_as_random gem'

end do |pkg|

pkg.gem_spec = spec

pkg.need_zip = true


After specify the above specification in rake file

projpath> rake gem

Now it will create a gem file in a “pkg” directory.

You can install this gem using

gemfolderpath> gem install your_new_gem.gem

Post comment if you feel it is useful for you.

Deploy on Server

Move Few Steps to Deploy Ruby code on Server

The Followings steps help you the deploy your ruby code on server from your local environment. you need to have capistrano 2.2.0 and railsmachine 1.0.0 installed locally or upgraded version.

1) Need to install rails-machine.

c:\> gem install railsmachine

if you find any problem then directly download .gem file from
After downloading the gem file try this.

c:\> gem install railsmachine-1.0.1.gem

2)Install Capistrano with all dependancies

gem install -y capistrano

if you find any problem then download directly from

3) Capify your application

c:> capify .

Now the deploy.rb file will created under /config/deploy.rb.

4) Configure Capistrano for Rails Machine

c:> railsmachine --apply-to . --name my_app --domain

5) Modify the deploy.rb as per your requirements(if any)

6) Deploy the Code

c:\ cap deploy

or,if you need to run migrations as well

c:\ cap deploy:migrations