One of the many advantages of rails is that it immediately gets you from zero to a functional application. To get started lets create a directory for the rails project called “railsproject”.
Now open the ruby command prompt and navigate to the directory that we just created. Run the rails new command to make your first rails application. Let us call our first rails application as “first”. The rails new command is a program that creates a skeleton rails application. It creates a standard file and directory structure that makes it easier than ever to organize and deploy files. All the rails application have a common file and directory structure making it easy to understand someone else’s code.
rails new first
After the file creation is done rails automatically runs the bundle install command which we will discuss later in this article. Upon successful execution of the rails new command, it will display the message “Your bundle is complete!”
Now lets have a quick look into the files and directories that have just been created. I use Aptana studio, an IDE for windows users of Rails.
Let’s learn more about the files that have been created.
The bundle install or the bundler command which we had seen in the beginning of this article installs the gems from the Gemfile. The bundler looks for the gems that needs to be installed from this file. Thus the Gemfil should contain the gems needed by your application.
source 'https://rubygems.org' gem 'rails', '3.2.8' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # To use Jbuilder templates for JSON # gem 'jbuilder' # Use unicorn as the app server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'debugger'
Signup for a Heroku account at https://api.heroku.com/signup
Then install heroku gem with the below command:
sudo gem install heroku
Remove ruby 1.9.2, install zlib and openssl package and then re-install ruby as follows:
rvm remove 1.9.2 rvm package install zlib rvm package install openssl rvm install 1.9.2 -C --with-zlib-dir=$HOME/.rvm/usr --with-openssl-dir=$HOME/.rvm/usr rvm --default use 1.9.2@rails3tutorial
Install and compile readline with the below commands:
sudo apt-get install libncurses5-dev sudo apt-get install libreadline5-dev cd ~/.rvm/src/ruby-1.9.2-p180/ext/readline/ ruby extconf.rb make make install
Associate your Heroku account with the public key.
Use create command to create a heroku subdomain for the app:
Using git to push the application to the heroku server:
git push heroku master
The open command opens up the url in a new browser window.
Ruby Version Manager (RVM) resolves versions conflicts when multiple versions of ruby is installed on the same system. It also enables quick and easy installation of ruby on rails on ubuntu. This article provides solution to the problems faced during the installation of ruby on rails on ubuntu using RVM.
Installation of RVM:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) source ~/.rvm/scripts/rvm rvm reload
Install Ruby 1.9.2 with rvm:
rvm package install zlib rvm install 1.9.2 -C --with-zlib-dir=$rvm_path/usr rvm install 1.8.7-p174 -C –with-zlib-dir=$rvm_path/usr
To resolve version conflict, create separate gemsets for each of the two different versions:
rvm --create 1.8.7-p174@rails2tutorial rvm --create use 1.9.2@rails3tutorial
To use Ruby 1.9.2 by default and Rails 3.0 give the below command:
rvm --default use 1.9.2@rails3tutorial
gem install --no-ri --no-rdoc --version=3.0.1 rails
Confirm installation with the below command. This command will display the version of rails installed on the system.
Installation of rvm automatically installs RubyGems
Give the below command to confirm this. This command would display the path in which the gem has been installed.
Update the system to the latest version with the below command:
gem update –system