Ruby on Rails Tutorial. Learn Rails by building an Example to-do list app.
This Ruby on Rails tutorial has a very web-development-centric approach. It is for people who are serious about developing their own apps in Ruby on Rails. The tutorial starts with a quick Ruby on Rails introduction which is useful for beginners. The rest of the tutorial teaches you to build an example to-do list app to help you get started with your own app.
While it is good to have some knowledge of Ruby, HTML & Linux, some people who are beginners with no programming background were also able to complete this tutorial. More on this on our philosophy page. If you are serious about web development in Ruby on Rails, you should give this tutorial a shot.
You can follow the tutorial to build the example app on your PC if you have Rails 3 installed. Else you can also use the Codelearn Playground, to your right, which is like a complete online Rails IDE, to follow the instructions & build your Ruby on Rails example to-do list app. We encourage you to use the Codelearn Playground as you would be able to test your app too.
Feel free to use the Question & Answer button on right bottom to ask any questions/doubts you have.
Module 1. Ruby on Rails introduction for beginners
A quick run down by showing an example Ruby on Rails site in action
- 1. Zero to app in 5 steps
- This Ruby on Rails tutorial lesson get you started with your first Rails app in 5 steps. The focus is on getting to see your app in action & not on explaining what each steps does. Start with 'rails new', edit Gemfile to include rubyracergem, do bundle install & run rails server to see your app in action.
- 2. Rails directory structure
- A default Rails app has lot of files & directories in it. This Ruby on Rails tutorial lesson mentions which are the important files/directories you should be concerned of namely public, app, config & Gemfile. It also shows the Gemfile structure & how bundle install uses Gemfile to install all your Rails app gems.
- 3. Say hello through Rails
- Every tutorial starts with Hello World. In this Ruby on Rails tutorial lesson, you will learn that if you dump a hello world file in public directory of your Rails app, it would be served by the rails server as is.
- 4. Pages using controller
- This Ruby on Rails tutorial lesson shows Rails controllers in action by letting you create two pages using 'rails generate controller' command. Generate the pages & then see the output inside App Output tab.
- 5. Visualizing Rails flow
- This Ruby on Rails tutorial lesson explains the Rails MVC (short form of Model View Controller) architecture by showing how the pages generated using the controller command are served. The complete Rails flow is shown using diagrams for easy understanding.
Module 2. Desigining a Ruby on Rails example app
Design a Rails app & fiddle with controllers, models & views.
- 1. Designing to-do list app
- Before starting to develop a Ruby on Rails app, you need to design the structure of the app. This Ruby on Rails tutorial lesson shows how to design a To-do list app by deciding on the URLs, mapping them to Rails Controller actions, optimizing Rails Views & deciding on what data Rails Model should hold.
- 2. Todos from controller
- Once you are done with a design, you get started by creating Rails controllers to map the URLs to appropriate action. This Ruby on Rails tutorial lesson teaches you that. Learn how to pass data from controllers to views through instance variables followed by a brief Ruby tutorial at the end.
- 3. Model to store/fetch todos
- A Rails app handles data through Rails models. This Ruby on Rails tutorial lesson shows you how to create a Todo model using 'rails generate model' command to handle the to-do list data. You learn database migration to add fields to the Model. You populate the Model through Rails console & then view the todos through the Todos controller.
- 4. Learning to delete last todo
- This Ruby on Rails tutorial lesson introduces a case when you need to add actions & views to existing Rails controller by creating a 'delete last todo' feature. You also learn to do some basic Model manipulation inside Rails controller code.
- 5. Add Twitter Bootstrap CSS
- Learn how to add Twitter Bootstrap CSS to your Rails app. The process teaches you how Rails view rending, layouts & assets pipeline work. This Ruby on Rails Tutorial lesson also introduce helper function link_to at the end.
Module 3. Enhancing the Ruby on Rails example app
Enhance Rails app through forms, checkboxes & error handling
- 1. Add todo from the view
- So far, a todo item has been entered through Rails console. This Ruby on Rails tutorial lesson teaches you to use forms (form_tag) in Rails to create a new todo item. Learn how to handle the handle form data in the controller through params variable & attr_accessible. Server side Rails form validation is introduced at the end.
- 2. Adding todo through form_for
- Change your Rails view code to use form_for instead of form_tag . form_for is a more popular Rails form helper function. Test your knowledge by adding a success message on successful addition of Todo from the form.
- 3. Mark todo complete
- Now that you can add todo items from a form, it is time to mark them complete. This Ruby on Rails tutorial lesson teaches you how to achieve the same using forms & checkboxes in the view. You introduce a new field 'completed' using database migration.
- 4. Edit & delete todos
- ... coming soon ...
- 5. Ajaxifying operations
- ... coming soon ...