Rails101 Contents
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
ME=`whoami`
sudo chown $ME:$ME -R simply_people/public
Let's go into the application:
cd simply_people
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
.title_box
.innertube
Menu
.navigation_box
.innertube
= link_to "People", people_path
%br
= link_to "Check CSS", :action=>'check_css', :controller=>'info'
%br
= 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
script/server
Now you can use the database
- http://localhost:3000 lands on the "welcome" page. If you edited the menu correctly you'll see the entry leading to people
- http://localhost:3000/people lands on the "people" page directly.
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
umuro:
first_name: Umur
last_name: Ozkul
birth_date: 1967-02-13
bart:
first_name: Bart
last_name: Leo
birth_date: 1968-05-20
uberto:
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
script/server
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:
- HAML
- ActiveScaffold
- Ruby on Rails with Relations Get into modeling and data consistency
- Rails Guides
- Rails Wiki
As well as commenting here, you can tweet or email to me
If you like this page, please spread the word: