Ruby on rails is an excellent framework for developing web apps using ruby. And to be clear, ruby on rails is not a language but it is a framework. Lot of people misunderstand ruby on rails as a language. Using ruby on rails you can develop a web application really faster as opposed to other frameworks. Ruby on rails is a developer friendly framework and it makes life so easily by doing most of the development work for you. IN this tutorials i will explain how to set up ruby on rails framework on your ubuntu machine and deploy a web application with postgreSQL database.
Setting Up Ruby On Rails environment:
1) For setting up the ruby on rails environment you need to have ruby installed in your workstation. Install the development tools first, it will install all the dependencies needed for ruby environment. And then install the latest ruby from the apt repository.
# sudo apt-get install build-essential
# sudo apt-get install ruby1.9.1
If you get any dependency error, just install those dependencies using apt. Also if you are running the old 1.8.7 version of ruby, make the system point to the newest version using the following command.
# sudo update–alternatives —config ruby
2) Now install rubygems using the following command.
# sudo apt-get install rubygems
3) Install rails framework using the following command.
# sudo gem install rails
The above command will install rails frame work and by default rails uses sqlite database and webrick webserver. So for testing you can use the webrick web server. You can deploy rails application using apache web server by installing the passenger module for apache.
4) Create a sample rails application using the following command.
# sudo rails new demo_app
The above command will automatically creates the necessary configuration files and folder for the rails app.
Installing And Setting Up PostgreSQL With Rails
1) Install postgreSQL using the following command
# sudo apt-get install postgreSQL
2) Install the gui for manaing the databases using the following command.
# sudo apt-get install pgadmin3
Use pgadmin3 in terminal to view the gui.
3) Now create a user “postgres”
# sudo -u postgres psql postgress
4) Set a password for the user postgres using the following command. It will prompt you to enter the password two times.
5) Login in to postgres user with root privileges to use the psql cli to manage databases using terminal.
# su postgres
6)Create a database using the following commmand.
# createdb db_name
/* db_name can be any user defined name
6)Access the database using cli using the followin command.
# psql db_name
7) The following commands are used to list the databases and tables.
# l —> lists all the available databases
# c —> lists the current database you are working with.
# d —> lists the tables associated with the database.
# d tablename —>shows the structure of the table.
Creating a Rails Application with PostgreSQL:
1. # rails new psql_demo -d postgresql
The above command will create the necessary config files and folders needed for rails application to use postgresql.
For further queries , leave a comment.