Ruby on Rails

I just started to learn Ruby on Rails. So I’d like to remember some stuff about the databases. This article is more like a small personal notebook. Or a notebook of cheat-sheet for N00b in Rails

Ruby was easy to grasp and I was able to do a very simplistic website in no time. See the github repo even though after a month not using it I feel I already forgot everything :P.

Especially the database handling seemed incredibly easy. This is only my opinion after a few weeks, not at all an expert opinion.

Basic of creation

  • To create a database :
rails g create database column:datatype column2:datatype2 ...
  • To add something to a database :
rails g migration add_thing_to_database thing:datatype

For example

rails g migration RemoveUnusefulFieldsFromUsers hair_color:string
  • To remove a column from a database :
rails g migration RemoveThingFromDatabase thing:datatype

After this two commands rake db:migrate

When creating controllers

rails g controller somethings

Take care the S is important !

On the terminal

  • rails server : create a server emulation locally. Test resulting site by going to http://localhost:3000/ on your browser

Github and Heroku

One need to switch to PostGre database.

I followed the fedora official instruction for PostGre (this is the french documentation that I used)

In you gem file :

#gem 'sqlite3', :group => :development
gem 'pg'

And in config/database.yml


  adapter: postgresql
  host: localhost
  encoding: unicode
  database: rumor_development
  pool: 5
  timeout: 5000
  username: [username]
  password: [actualpasswordofthedatabase]

  adapter: postgresql
  encoding: unicode
  database: rumor_test
  pool: 5
  timeout: 5000
  username: [username]
  password: [actualpasswordofthedatabase]

  adapter: postgresql
  database: rumor_production
  pool: 5
  timeout: 5000
  username: [username]
  password: [actualpasswordofthedatabase]

Then the upload to heroku should work out with : git push heroku master. Attention, do not forget to commit your change to git before uploading to heroku 😉


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s