Setting up a new Rails3 application

After doing some initial work to get Ruby 1.9.1 working, now it is time to get the application set up. I started with Dr. Nic’s post and experimented a little. Here is how it goes:

~/projects[]$ rvm use 1.9.1
<i> Now using ruby 1.9.1 p243 </i>

Then the newest Rails:

~/projects[]$ git clone git://github.com/rails/rails.git
~/projects[]$ ruby rails/railties/bin/rails -v
Rails 3.0.pre

To generate an application (let’s call it edge), the usual command is there:

~/projects[]$ ruby rails/railties/bin/rails edge -d mysql

Git is an awesome SCM system and now it is the right time to init version control:

~/projects/edge[]$ git init
~/projects/edge[master]$ cat .gitignore
*.log
~/projects/edge[master]$ git add .
~/projects/edge[master]$ git commit -m 'Generated new app with rails edge -d mysql'

One of the first niceties that welcome you in Rails3 is bundler. Just like rake gems:unpack it allows for bundling all the gems with your application, so you do not need to install gems everywhere you develop/deploy your application. Only bundler is more flexible. For now just the basics:

~/projects[]$ cd edge/
~/projects/edge[]$ cat Gemfile
# Edit this Gemfile to bundle your application's dependencies.

gem "rails", "3.0.pre"

## Bundle edge rails:
# gem "rails", :git => "git://github.com/rails/rails.git"

## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
# gem "sqlite3-ruby", :require_as => "sqlite3"
# gem "aws-s3", :require_as => "aws/s3"

## Bundle gems used only in certain environments:
# gem "rspec", :only => :test
# only :test do
#   gem "webrat"
# end

As you can see, you can even define gems needed for separate environments!

For now I just use the most basic gems:

~/projects/edge[]$ cat Gemfile
gem "rack",       "~> 1.0.1"
gem "rack-mount",            :git => "git://github.com/rails/rack-mount.git"
gem "rack-test",             :git => "git://github.com/brynary/rack-test.git"
gem "rake",       "~> 0.8.7"
gem "arel",                  :git => "git://github.com/rails/arel.git"
gem "abstract",   "~> 1.0.0"
gem "erubis",     "~> 2.6.5"
gem "mysql",      "~> 2.8.1"
gem "rails",      "3.0.pre", :git => "git://github.com/rails/rails.git"

But to use the bundler it has to be installed first:

~/projects/edge[master]$ gem install bundler

And before I bundle the application gems, I will follow the advice and git-ignore some more directories:

~/projects/edge[master]$ cat .gitignore
*.log
bin/*
vendor/gems/*
!vendor/gems/cache/

Using bundler is as easy as running:

~/projects/edge[master]$ gem bundle
Calculating dependencies...
Cloning git repository at: git://github.com/rails/rack-mount.git
Cloning git repository at: git://github.com/brynary/rack-test.git
Cloning git repository at: git://github.com/rails/arel.git
Cloning git repository at: git://github.com/rails/rails.git
Updating source: http://gems.rubyforge.org
Downloading abstract-1.0.0.gem
Downloading erubis-2.6.5.gem
Downloading multimap-1.0.2.gem
Downloading mysql-2.8.1.gem
Downloading rack-1.0.1.gem
Downloading rake-0.8.7.gem
Installing multimap (1.0.2)
Building native extensions.  This could take a while...
Installing rake (0.8.7)
Installing mysql (2.8.1)
Building native extensions.  This could take a while...
Installing abstract (1.0.0)
Installing erubis (2.6.5)
Installing rack (1.0.1)
Done.

After:

~/projects/edge[master]$ git add . && git commit -m 'Bundled initial gems'

we are finished for this post.

Advertisements

Tags: ,

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


%d bloggers like this: