Wiley
Wiley.com
Print this page Share

Beginning Ruby on Rails

ISBN: 978-0-470-06915-8
408 pages
November 2006
Beginning Ruby on Rails (0470069155) cover image
Ruby on Rails is the revolutionary online programming tool that makes creating functional e-commerce web sites faster and easier than ever. With the intuitive, straightforward nature of Ruby and the development platform provided by Rails, you can put together full-fledged web applications quickly, even if you're new to web programming.

You will find a thorough introduction to both Ruby and Rails in this book. You'll get the easy instructions for acquiring and installing both; understand the nature of conditionals, loops, methods, and blocks; and become familiar with Ruby's classes and objects. You'll learn to build Rails applications, connect to databases, perform necessary testing, and put the whole thing together to create real-world applications such as shopping carts and online catalogs--apps you can actually use right away.

What you will learn from this book
* How to install and use Ruby and Rails
* Object-oriented programming with Ruby
* Rails fundamentals and how to create basic online applications
* How to work with HTML controls, use models in Rails applications, and work with sessions
* Details on working with databases and creating, editing, and deleting database records
* Methods for handling cookies and filters and for caching pages
* How to connect Rails with Ajax

Who this book is for

This book is for anyone who wants to develop online applications using Ruby and Rails. A basic understanding of programming is helpful; some knowledge of HTML is necessary.

Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved.
See More
Acknowledgments.

Introduction.

Chapter 1: Welcome to Ruby.

Creating a First Web Application.

Getting Started with Ruby.

Checking the Ruby Documentation.

Working with Numbers in Ruby.

Working with Strings in Ruby.

Storing Data in Variables.

Creating Constants.

Interpolating Variables in Double-Quoted Strings.

Reading Text on the Command Line.

Creating Symbols in Ruby.

Working with Operators.

Handling Operator Precedence.

Working with Arrays.

Using Two Array Indices.

Working with Hashes.

Working with Ranges.

Chapter 2: Conditionals, Loops, Methods, and Blocks.

It’s All about Making Choices: the if Statement.

Using the case Statement.

Using Loops.

Creating and Calling a Method.

Making Use of Scope.

Working with Blocks.

Chapter 3: Classes and Objects.

All about Encapsulation.

Creating a Class.

Creating an Object.

Basing One Class on Another.

Understanding Ruby’s Object Access.

Overriding Methods.

Creating Class Variables.

Creating Class Methods.

Creating Modules.

Creating Mixins.

Chapter 4: Welcome to Rails.

Putting Ruby on Rails.

Introducing Model-View-Controller Architecture.

Giving the View Something to Do.

Mixing Ruby Code and HTML Inside the View.

Passing Data from an Action to a View.

Escaping Sensitive Text.

Adding a Second Action.

Chapter 5: Building Simple Rails Applications.

Accessing Data the User Provides.

Using Rails Shortcuts for HTML Controls.

Working with Models.

Tying Controls to Models.

Initializing Data in Controls.

Storing Data in Sessions.

Chapter 6: Connecting to Databases.

Tutorial on Databases.

Creating a Data-Aware Rails Application.

Creating the Database.

Running the store Application.

Adding Another Record.

Beautifying the Display.

Chapter 7: Working with Databases.

Displaying Items to the Customer.

Creating a Shopping Cart.

Combining Purchases in the Cart.

Clearing the Cart.

Letting the User View the Cart Anytime.

Chapter 8: Validating and Testing.

Validating the Presence of Data.

Validating if Data Is Numeric.

Validating if Data Is Unique.

Creating the Validator Application.

Writing Your Own Validate Method.

Testing Your Model.

Testing Your Controller.

Chapter 9: Controlling the Action with the Action Controller.

Routing Refinements.

Creating Cookies.

Creating a Filter.

Logging in with Filters.

Using After Filters.

Rendering Text Directly.

Caching.

Chapter 10: Getting the Big Picture with Views.

Creating XML.

Creating XML Attributes.

Using View Helpers.

Using View Pagination.

Using Partial Templates.

Passing Data to Partial Templates.

Chapter 11: Ajax and Rails.

Using Ajax.

Getting Access to Ajax Data.

Using XML and Ajax.

Using HTML Controls and Ajax.

Performing Ajax Searches.

Performing Visual Effects.

Appendix A: Answers to Exercises.

Index.

See More
Steven Holzner is the award-winning author of more than 100 programming books. He’s been involved in Ruby on Rails for a long time, and does commercial Rails development. He’s also been on the faculty of Cornell University and MIT, as well as having been a contributing editor for PC Magazine.
See More
Download TitleSizeDownload
Download Code
The code examples for this title are stored in a ZIP archive. To open it, you will need a computer with software capable of opening ZIP files. If you do not already have this capability, you can download a free trial of WinZip.
2.34 MB Click to Download
See More

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
60 Typo
First Sentence:
clocks

should be:
blocks
02/19/07
69-71 Error in Text
The output of the code:
The new dog is brown

should be:
The new animal is brown
01/16/07
94 Error in Directory Path
under "Creating the controller":
rubydev\ch04\first\controllers directory

should be:
rubydev\ch04\first\app\controllers
02/19/07
139 Error in Text
C:\rubydev\ch05\modeler>ruby script/server

should be:
C:\rubydev\ch05\textfields2>ruby script/server
02/06/07
144 Error in Text
http//localhost3000/input.html

should be:
http//localhost3000/look/at
02/06/07
147 Error in Step
step 9:
http://localhost:3000/input.html

should be:
http://localhost:3000/look/input
02/19/07
5 154, 155 Error in Code
pg 144:
5. Create a new view template for the application, rubydev\ch05\textfields2\app\views\look\input.rhtml

should be:
5. Create a new view template for the application, rubydev\ch05\session\app\views\look\at.rhtml

THEN

pp 155, to invoke it:
localhost:3000/look/at
01/04/07
167 Error in Text
C:\>cd \rubydev\ch06\store>ruby

should be:
C:\>cd \rubydev\ch06\store
02/06/07
193 Error in Code
2nd highlighted block:
:order => "name description"

should be:
:order => "name, description"
12/27/2007
216 Error in Text
@cart.initializeinitialize

should be:
@cart.initialize
02/06/07
231 Error in Text
validates_numericality_of.

Should be:
validates_uniqueness_of.
05/21/07
235 Error in Code
"Try It Out", Step 1:
code line:
validates_inclusion_of :data, :in=> 1..99, :message => "is out of bounds"
should be:
validates_inclusion_of :data, :in=> '1'..'99', :message => "is out of bounds"
1/25/07
245 Error in Text
Below figure 8-17 reads:
various options you can set with validates_confirmation_of.

should read:
various options you can set with validates_length_of.
03/05/07
274 Error in Code (2)
if (Time.now.hour >= 9 && Time.now.hour <== 17)

should be:
if (Time.now.hour >= 9 && Time.now.hour <= 17)

the error is repeated on this page
05/17/07
275 Error in URL
step 11:
Navigate to http://localhost:3000/play/game

should be:
Navigate to http://localhost:3000/play/now
05/17/07
285 Error in Command
step 1:
rails login

should be:
rails copyrighter
05/17/07
11 330 Error in Code
In part 5 of the Using XML and Ajax Try it out section:

'var xmlDocment = request.responseXml'

might have to be:

'var xmlDocument = request.responseXML'.

(note: some browsers might require capitalization)
08/13/2007
5 Error in Code
Step #4
Create a new file, rubydev\ch05\textfields\public\input.html, adding this code:

<html>
<head>
<title>Using Text Fields</title>
</head>
<body>
<h1>Working With Text Fields</h1>
This Ruby on Rails application lets you read data from text fields.
<br>
<form action = "\look\at" >
Please enter your name.
<br>
<input type="text" name="text1">
<br>
<br>
<input type="submit"/>
</form>
</body>
</html>

the code <form action = "\look\at" > is problematic, as the URI scheme, used by html, does not allow for backslashes ("\").

the correct syntax would be <form action = "/look/at" >.

though the former works on internet explorer 6, it does not on firefox.


http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax"
07/24/2007
See More
Buy Both and Save 25%!
+

Beginning Ruby on Rails (US $34.99)

-and- Teach Yourself VISUALLY Adobe Muse (US $29.99)

Total List Price: US $64.98
Discounted Price: US $48.73 (Save: US $16.25)

Buy Both
Cannot be combined with any other offers. Learn more.

Related Titles

Back to Top