Subscribe in a reader
Subscribe by Email
Contact Umur Ozkul
Blog » Rails101 Getting Started with RAD Ruby on Rails
Posted on 09 May 2009 00:06
You might be just starting to learn Ruby on Rails fresh. You might be looking for a way of RAD development on Rails. Here is the Ruby on Rails tutorial. This article is in [[Rails101].
Basic Ruby on Rails Installation
This is Outdated. Does not apply to Rails 3.x
UPDATE: Using Hobo Edge On Rails 3 describes installing gems for both Rails 2 and Rails 3 in addition to installing Hobo on Rails3.
Read Using Hobo Edge On Rails 3 and exit(0)
How to Install Ruby on Rails 2.3.X in Ubuntu 9.04, 10.04, 10.10 . This strategy is not verified yet for Rails 3
First, edit /etc/environment file so that the path change above is permanent. Otherwise sudo below will fail. Mine is like this:
Running the script1 below, your machine is ready for basic Ruby on Rails development
If you see "could not find rubygems update in any repository" then this is the solution: http://www.searchmarked.com/ubuntu/could-not-find-rubygems-update-0-in-any-repository.php . If your gems env is totally outdated you might need to apply: http://wiki.rubyonrails.org/getting-started/installation/linux-ubuntu
sudo apt-get install ruby-full -y sudo apt-get install build-essential -y sudo apt-get install git-core -y sudo apt-get install rubygems PATH=$PATH:/var/lib/gems/1.8/bin sudo gem install rubygems-update sudo su -c update_rubygems sudo gem install rails --version 2.3.10 sudo gem install mongrel sudo apt-get install sqlite3 libsqlite3-dev sudo gem install sqlite3-ruby
Now you can proceed to Ruby on Rails with One Model
(If you have a prior Ruby installation to this then prevent multiple conflicting gem libraries)
Download Ruby and Gems from http://rubyonrails.org/download.
Complete windows equivalent of my setup is detailed in http://wiki.rubyonrails.org/getting-started/installation/windows. Go for SQLite there.
My personal idea is that one should use http://VirtualBox.org to create an Ubuntu or Kubuntu vm for yourself and use it as your development machine. Installing things on Window is much more complicated and you'll miss the wealth of free applications on Linux. That applies if you are not calling your C# libraries from Ruby :)
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 application2.
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:
And create our first model5:
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
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
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:
- Ruby on Rails with Relations Get into modeling and data consistency
- Rails Guides
- Rails Wiki
If you like this page, please spread the word:
You can contact me if you have questions or corrections.
on iPhone, iPad, AppleTV, PC, Roku. Try free!