Creating First Rails 3 App on Windows 7

I followed some rails books to learn the framework, but I find that some commands have been changed and it took me a while to find out their new versions.

So here is how I created my first rails 3 app on Windows 7 machine, howto create models with SQLite 3 and start the web server.

Of course the first step is opening command prompt and creating app.

rails new testApp

After that I used scaffold command to produce model, view controller and migration files. Note that you should navigate to your rails app to run below command

rails generate scaffold book title:string desc:string

After creating migration file, we need to apply “unapplied migrations” to database. Here is how I did this:

rake db:migrate

After creating app with models and db migration, now lets start WEBrick-based web server and see what we did.

ruby script/rails server

Above command will start the server and it will run until we press ctrl-c combination in command prompt.

If you want to change table you’ve created, here is the command which creates a new migration:

ruby script/rails generate migration add_price_field_to_book price:decimal

Remember you should run “rake db:migrate” command in order to apply to database!

Creating new controller:

ruby script/rails generate controller gallery index

P.S 1 : In case you know .Net and new to RoR just like me, master file is ‘application.html.erb’ in RoR, under views/layouts folder.

P.S 2: I’m using Aptana RadRails as Editor and it’s good so far.

 

Tags: , , , , ,

Comments

No comments so far.

  • Leave a Reply
     
    Your gravatar
    Your Name