Tutorial: Ruby On Rails With One Model

This tutorial is depreciated. It won't be upgraded to Rails 3. I am using Hobo instead of ActiveScaffold and rails templates now. See hobo-organizations for an example of really quickly making a simple rails application

Also I suggest [[blog:all-about-testing-hobo-organizations-revisited]]] which covers my testing experience.

Here comes the demo. Let's quickly create a Ruby on Rails application. If you don't have ruby then do * Basic Ruby on Rails Installation first. Then you'll be able to create this:


First, create the application1.

rails simply_people -m http://tinyurl.com/cs-active-scaffold
sudo chown $ME:$ME -R simply_people/public

Let's go into the application:

cd simply_people

Only on Windows:23

rake gems:install

And create our first model4:

script/generate cs_active_scaffold Person first_name:string last_name:string birth_date:date
rake db:migrate

At this point edit "app/views/cs_global/_application_menu.html.haml" and make it look like

    = link_to "People", people_path
    = link_to "Check CSS", :action=>'check_css', :controller=>'info'
    = link_to "About Rails", '/about_rails.html'

Be careful, no tabs. All indentation must be spaces (multiples of 2 spaces). This is an HAML file which happens to be more readable and powerful than HTML.

Let's start the server


Now you can use the database

Of course the first thing to do is to press the "Create New" link and create some records. Don't forget to check how the calendar on birth date field works. Try sorting the data on different fields. Press "Search' and filter the data according to a name, etc.

But instead of manually entering data you can upload test data to try the application.

Edit "test/test/fixtures/people.yml" and make it look like:

 Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

  first_name: Umur
  last_name: Ozkul
  birth_date: 1967-02-13

  first_name: Bart
  last_name: Leo
  birth_date: 1968-05-20

  first_name: Uberto
  last_name: Orsini
  birth_date: 1969-05-22

To load the test data to the database. Execute

rake db:fixtures:load

Make sure it's serving if you had stopped it


Now you should see this!


At any time you can reset the database structure and data to reload the data.

rake db:migrate VERSION=0
rake db:migrate
rake db:fixtures:load

It was simple. Isn't it? Now you have a qualified online database :)

Of course, just building a single table application is not enough. Rails takes care of the application. You only need to focus on programming the model classes. Let's do some model programming!

What is next?

As you have the ability now to create a project instantly and wire your relations, you can dive into the further details of ruby and rails at your leisure:

As well as commenting here, you can tweet or email to me

If you like this page, please spread the word: diggdel.icio.usFacebook

Related Discussions

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License