Sunday, April 13, 2014

Ruby on rails-The first application

rails new first_app
cd first_app/

Update Gemfile with an explicit version for each Ruby gem. 
************************************** 
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.4'

group :development do
  gem 'sqlite3', '1.3.8'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end
*************************************** 
$ bundle update
$ bundle install
$ rails server

So far So good :):)

Git for version control

To install Git, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv.

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
 libz-dev libssl-dev
$ apt-get install git
$ git config --global user.name "Your Name"
$ git config --global user.email your.email@example.com

Setup repository

$ git init
Rails command creates a default .gitignore file in the application root directory, causing Git to ignore file mention inside it.

$ git add .      
# dot ‘.’ represents the current directory, and Git is smart enough to add the files recursively,So it automatically includes all the subdirectories.It adds the project files to a staging area, which contains pending changes to your project;
$ git status      
# see which files are in the staging area using this command.
$ git commit -m "Initialize repository" 

# Tells Git you want to keep the changes.
$ git log 

# See a list of your commit messages ,To exit git log, you may have to type q to quit.

Generate SSH Key
https://help.github.com/articles/generating-ssh-keys

GitHub

$ git remote add origin https://github.com//first_app.git
$ git push -u origin master
# Tells Git that you want to add GitHub as the origin for your main (master) branch and then push your repository up to GitHub.

Deployment

Lets use Heroku, a cloud deployment service.
Heroku uses the PostgreSQL database, which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres.

A Gemfile with added gems and explicit Ruby version:

******************************** 
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.4'

group :development do
  gem 'sqlite3', '1.3.8'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end
*******************************
 
$ bundle install --without production 

The --without production option prevents the local installation of any production gems, which in this case consists of pg and rails_12factor.

$ git commit -a -m "Update Gemfile.lock for Heroku"
 
Create and configure a new Heroku account.
Install heroku:  https://toolbelt.heroku.com/debian.
Upload your public key to Heroku.


$heroku keys:add ~/.ssh/id_rsa.pub

If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:

$ heroku keys:add
$ heroku logs

Running the logs 'heroku logs', has a key giveaway: PG::Error: ERROR: relation "" does not exist. This entry states your model could not be loaded. To provide an update to previous answers, heroku rake has been deprecated. Heroku requires:

$ heroku run rake db:migrate




$ heroku login
 
 
Navigate back to your Rails project directory and use the heroku command to create a place on the Heroku servers for the sample app to live.
$ cd ~/rails_projects/first_app
$ heroku create

$ git push heroku master
$ heroku open 

No comments:

Post a Comment