Ruby on Rails 2.1

Ruby on Rails 2.1

Ruby on Rails 2.1 About the Tutorial Ruby on Rails is an extremely productive web application framework written in Ruby by David Heinemeier Hansson. This tutorial gives you a complete understanding on Ruby on Rails 2.1. Audience This tutorial has been designed for beginners who would like to use the Ruby framework for developing database-backed web applications. Prerequisites Before you start Ruby on Rails, please make sure you have a basic understanding on the following subjects: Ruby syntax and language constructs such as blocks. Relational databases and SQL. HTML documents and CSS. Copyright & Disclaimer Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i Ruby on Rails 2.1 Table of Contents About the Tutorial ...................................................................................................................................... Audience .................................................................................................................................................... i Prerequisites .............................................................................................................................................. i Copyright & Disclaimer .............................................................................................................................. i Table of Contents ...................................................................................................................................... ii 1. INTRODUCTION ..................................................................................................................... 1 What is Ruby? ........................................................................................................................................... 1 Why Ruby? ............................................................................................................................................... 1 Sample Ruby Code .................................................................................................................................... 2 Embedded Ruby ........................................................................................................................................ 2 What is Rails? ........................................................................................................................................... 3 Full Stack Framework ................................................................................................................................ 4 Convention over Configuration ................................................................................................................. 4 Don't Repeat Yourself (DRY) ..................................................................................................................... 4 Rails Strengths .......................................................................................................................................... 4 What is Rails 2.1.0? ................................................................................................................................... 5 2. INSTALLATION ....................................................................................................................... 6 Rails Installation on Windows ................................................................................................................... 6 Rails Installation on Mac OS X ................................................................................................................... 7 Rails Installation on Linux ......................................................................................................................... 7 Keeping Rails Up-to-Date .......................................................................................................................... 8 Installation Verification ............................................................................................................................ 8 How to Upgrade? ...................................................................................................................................... 9 ii Ruby on Rails 2.1 3. FRAMEWORK ...................................................................................................................... 10 Ruby on Rails MVC Framework ............................................................................................................... 10 Representation of MVC Framework ........................................................................................................ 11 Directory Representation of MVC Framework ........................................................................................ 12 4. DIR STRUCTURE .................................................................................................................. 13 5. EXAMPLES ........................................................................................................................... 16 Workflow for Creating Rails Applications ................................................................................................ 16 Creating an Empty Rails Application ....................................................................................................... 16 Starting Web Server ................................................................................................................................ 17 6. DATABASE SETUP ................................................................................................................ 19 Configuring database.yml ....................................................................................................................... 19 7. ACTIVE RECORDS ................................................................................................................ 21 Translating a Domain Model into SQL ..................................................................................................... 21 Creating Active Record Files .................................................................................................................... 21 Creating Associations between Models .................................................................................................. 22 Implementing Validations ....................................................................................................................... 23 8. MIGRATIONS ....................................................................................................................... 24 What can Rails Migration Do? ................................................................................................................. 24 Create the Migrations ............................................................................................................................. 25 Edit the Code to Tell it What to Do .......................................................................................................... 25 Run the Migration ................................................................................................................................... 27 Running Migrations for Production and Test Databases ......................................................................... 27 9. CONTROLLERS ..................................................................................................................... 28 iii Ruby on Rails 2.1 Implementing the list Method ................................................................................................................ 29 Implementing the show Method............................................................................................................. 29 Implementing the new Method .............................................................................................................. 30 Implementing the create Method ........................................................................................................... 30 Implementing the edit Method ............................................................................................................... 31 Implementing the update Method .......................................................................................................... 31 Implementing the delete Method ........................................................................................................... 31 Additional Methods to Display Subjects.................................................................................................. 32 10. VIEWS ................................................................................................................................. 34 Creating View File for list Method ..........................................................................................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us