Install and run a simple application in ruby on rails (feodra & ubuntu)


Here is the Instruction that you have to follow to install ruby on rails. Instead of yum, use apt-get if you are using ubuntu.

Step 1: install ruby yum install ruby

Step 2: Install rubygems yum install rubygems

note: It will ask for installing dependencies, Press Y each time

Step 3: Now install rails gem install rails

You are done. :)
Now try to run a simple application using ruby on rails.

Create a folder in any directory (suppose its “myproject”) and our project name is simpleapp so from command prompt go to that folder (myproject).

now type

rails simpleapp -d mysql

i.e: -d mysql is for using mysql database. if u r using sqlite3 then just omit these text.

Anyway, after running this rails it will automatically create all the necessary files with a configuration file for mysql. Go to myproject/simpleapp/config/ directory. You will find database.yml file. Open the file you’ll the configuration for 3 database for 3 different mood. By default it always use development mood. So edit the configuration of development mood.

You will see that, it has configured the database name as simpleapp_development.

Edit this name or create new database in the mysql with this name or the edited db name.

Now we will try to build an AMD(add-modify-delete) tool using ruby on rails. For this initially we will use scaffold feature of ruby on rails.

In the command prompt go to your application directory and type

script/generate scaffold post title:string body:text

Once scaffolding is successful then migrate database. To migrate database type

rake db:migrate

Now just run the server and view your application. In order to run the server type

script/server

After running the server you will see that its listening to the port localhost:3000 or 127.0.0.1:3000 . That means you can view your application in that port of your web browser.

Open firefox and type localhost:3000/posts (posts is the controller name) to see your application.

yup. that’s all done. Isn’t it too simple ? :)

  1. #1 by zaman - March 1st, 2009 at 17:39

    Need to install ruby on rails in my pc. but i am using windows xp. I googled a lot to install ruby on rails in my pc but messed up everything. Please give me instruction about how to install ruby on rails in windows xp.

(will not be published)
  1. No trackbacks yet.