How to use this Book: Intro
Who is this book for?
If you can answer âyesâ to all of these:
Are you comfortable with HTML?
Do you have some experience of a computer language like Java, C# or PHP?
Do you want to build cool stuff for the web in a fraction of the time it used to take?
this book is for you.
Who should probably back away from this book?
If you can answer âyesâ to any of these:
Are you someone who doesnât have any experience with HTML?
Are you an accomplished Rails developer looking for a reference book?
Are you afraid to try something different? Would you rather have a root canal than mix stripes with plaid? Do you believe a technical book canât be serious if it anthropomorphizes clients and servers?
this book is not for you.
We know what youâre thinking
âHow can this be a serious Rails book?â
âWhatâs with all the graphics?â
âCan I actually learn it this way?â
We know what your brain is thinking
Your brain craves novelty. Itâs always searching, scanning, waiting for something unusual. It was built that way, and it helps you stay alive.
So what does your brain do with all the routine, ordinary, normal things you encounter? Everything it can to stop them from interfering with the brainâs real jobârecording things that matter. It doesnât bother saving the boring things; they never make it past the âthis is obviously not importantâ filter.
How does your brain know whatâs important? Suppose youâre out for a day hike and a tiger jumps in front of you, what happens inside your head and body?
Neurons fire. Emotions crank up. Chemicals surge.
And thatâs how your brain knows...
This must be important! Donât forget it!
But imagine youâre at home, or in a library. Itâs a safe, warm, tiger-free zone. Youâre studying. Getting ready for an exam. Or trying to learn some tough technical topic your boss thinks will take a week, ten days at the most.
Just one problem. Your brainâs trying to do you a big favor. Itâs trying to make sure that this obviously non-important content doesnât clutter up scarce resources. Resources that are better spent storing the really big things. Like tigers. Like the danger of fire. Like the winners of the last three seasons of American Idol. And thereâs no simple way to tell your brain, âHey brain, thank you very much, but no matter how dull this book is, and how little Iâm registering on the emotional Richter scale right now, I really do want you to keep this stuff around.â
Metacognition: thinking about thinking
If you really want to learn, and you want to learn more quickly and more deeply, pay attention to how you pay attention. Think about how you think. Learn how you learn.
Most of us did not take courses on metacognition or learning theory when we were growing up. We were expected to learn, but rarely taught to learn.
But we assume that if youâre holding this book, you really want to master Rails. And you probably donât want to spend a lot of time. If you want to use what you read in this book, you need to remember what you read. And for that, youâve got to understand it. To get the most from this book, or any book or learning experience, take responsibility for your brain. Your brain on this content.
The trick is to get your brain to see the new material youâre learning as Really Important. Crucial to your well-being. As important as a tiger. Otherwise, youâre in for a constant battle, with your brain doing its best to keep the new content from sticking.
So just how DO you get your brain to treat Rails like it was a hungry tiger?
Thereâs the slow, tedious way, or the faster, more effective way. The slow way is about sheer repetition. You obviously know that you are able to learn and remember even the dullest of topics if you keep pounding the same thing into your brain. With enough repetition, your brain says, âThis doesnât feel important to him, but he keeps looking at the same thing over and over and over, so I suppose it must be.â
The faster way is to do anything that increases brain activity, especially different types of brain activity. The things on the previous page are a big part of the solution, and theyâre all things that have been proven to help your brain work in your favor. For example, studies show that putting words within the pictures they describe (as opposed to somewhere else in the page, like a caption or in the body text) causes your brain to try to makes sense of how the words and picture relate, and this causes more neurons to fire. More neurons firing = more chances for your brain to get that this is something worth paying attention to, and possibly recording.
A conversational style helps because people tend to pay more attention when they perceive that theyâre in a conversation, since theyâre expected to follow along and hold up their end. The amazing thing is, your brain doesnât necessarily care that the âconversationâ is between you and a book! On the other hand, if the writing style is formal and dry, your brain perceives it the same way you experience being lectured to while sitting in a roomful of passive attendees. No need to stay awake.
But pictures and conversational style are just the beginning...
Hereâs what WE did:
We used pictures, because your brain is tuned for visuals, not text. As far as your brainâs concerned, a picture really is worth a thousand words. And when text and pictures work together, we embedded the text in the pictures because your brain works more effectively when the text is within the thing the text refers to, as opposed to in a caption or buried in the text somewhere.
We used redundancy, saying the same thing in different ways and with different media types, and multiple senses, to increase the chance that the content gets coded into more than one area of your brain.
We used concepts and pictures in unexpected ways because your brain is tuned for novelty, and we used pictures and ideas with at least some emotional content, because your brain is tuned to pay attention to the biochemistry of emotions. That which causes you to feel something is more likely to be remembered, even if that feeling is nothing more than a little humor, surprise, or interest.
We used a personalized, conversational style, because your brain is tuned to pay more attention when it believes youâre in a conversation than if it thinks youâre passively listening to a presentation. Your brain does this even when youâre reading.
We included more than 80 activities, because your brain is tuned to learn and remember more when you do things than when you read about things. And we made the exercises challenging-yet-do-able, because thatâs what most people prefer.
We used multiple learning styles, because you might prefer step-by-step procedures, while someone else wants to understand the big picture first, and someone else just wants to see an example. But regardless of your own learning preference, everyone benefits from seeing the same content represented in multiple ways.
We include content for both sides of your brain, because the more of your brain you engage, the more likely you are to learn and remember, and the longer you can stay focused. Since working one side of the brain often means giving the other side a chance to rest, you can be more productive at learning for a longer period of time.
And we included stories and exercises that present more than one point of view, because your brain is tuned to learn more deeply when itâs forced to make evaluations and judgments.
We included challenges, with exercises, and by asking questions that donât always have a straight answer, because your brain is tuned to learn and remember when it has to work at something. Think about itâyou canât get your body in shape just by watching people at the gym. But we did our best to make sure that when youâre working hard, itâs on the right things. That youâre not spending one extra dendrite processing a hard-to-understand example, or parsing difficult, jargon-laden, or overly terse text.
We used people. In stories, examples, pictures, etc., because, well, because youâre a person. And your brain pays more attention to people than it does to things.
Hereâs what YOU can do to bend your brain into submission
So, we did our part. The rest is up to you. These tips are a starting point; listen to your brain and figure out what works for you and what doesnât. Try new things.
Slow down. The more you understand, the less you have to memorize.
Donât just read. Stop and think. When the book asks you a question, donât just skip to the answer. Imagine that someone really is asking the question. The more deeply you force your brain to think, the better chance you have of learning and remembering.
Do the exercises. Write your own notes.
We put them in, but if we did them for you, that would be like having someone else do your workouts for you. And donât just look at the exercises. Use a pencil. Thereâs plenty of evidence that physical activity while learning can increase the learning.
Read the âThere are No Dumb Questionsâ
That means all of them. Theyâre not optional sidebars, theyâre part of the core content! Donât skip them.
Make this the last thing you read before bed. Or at least the last challenging thing.
Part of the learning (especially the transfer to long-term memory) happens after you put the book down. Your brain needs time on its own, to do more processing. If you put in something new during that processing time, some of what you just learned will be lost.
Talk about it. Out loud.
Speaking activates a different part of the brain. If youâre trying to understand something, or increase your chance of remembering it later, say it out loud. Better still, try to explain it out loud to someone else. Youâll learn more quickly, and you might uncover ideas you hadnât known were there when you were reading about it.
Drink water. Lots of it.
Your brain works best in a nice bath of fluid. Dehydration (which can happen before you ever feel thirsty) decreases cognitive function.
Listen to your brain.
Pay attention to whether your brain is getting overloaded. If you find yourself starting to skim the surface or forget what you just read, itâs time for a break. Once you go past a certain point, you wonât learn faster by trying to shove more in, and you might even hurt the process.
Your brain needs to know that this matters. Get involved with the stories. Make up your own captions for the photos. Groaning over a bad joke is still better than feeling nothing at all.
Practice writing Rails applications!
Thereâs only one way to truly master Rails programming: program Rails applications. And thatâs what youâre going to do throughout this book. The best way to understand a subject is by doing it. Activity strengthens the neural pathways, so weâre going to give you a lot of practice: every chapter has apps that weâll build. So donât just skip over themâa lot of learning happens when you build these apps yourself. And donât worry if you make mistakes. Your brain actually learns more quickly from mistakes than it does from successes. Finally, make sure you understand whatâs going on before moving on to the next part of the book. Each chapter builds on the chapters that come before it.
This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is weâre working on at that point in the book. And the first time through, you need to begin at the beginning because the book makes assumptions about what youâve already seen and learned.
Before you begin this book you will need to get Ruby on Rails installed on your machine.
This is not a how-to book, so we donât have any chapters that give you instructions on how to install Ruby on Rails on your computer. Itâs better to get that kind of information from the web. You will need to install Ruby on Rails version 2.1 or above, as well as SQLite 3. You can find out more from
This is not a reference book.
So donât expect to see lots and lots of pages explaining 15 different ways to do something. We want you to understand by doing, so right from the get-go, weâll give you just enough information to move your learning forward. By the end of the book, you will have a mental framework of how Rails works and what it can do. You will then be able to slot the reference material into your brain much more rapidly and meaningfully than you would have been able to before. Psychologists call this the ability to chunk information.
All of the code in this book is available on the Head First site.
Weâll present all of the code youâll need as we go along. Itâs a good idea to program along with the book, and itâs a great idea to play around with the code and make it do your own thing. But sometimes you may want a copy of the code used in each chapter, so weâve made it available on the Head First Labs web site. Rails applications are quite self-contained, so thereâs no reason why you canât have the code that does what the book says it should do, alongside your own buffed and pimped out version. You can download the code from
We donât fully explain every piece of code.
Rails can generate a lot of code for you, and we donât want you to get bogged down in line-by-line descriptions. Weâll describe the important parts that you need to know, and then weâll move on. Donât worryâby the end of the book, all of the pieces should fall into place.
This is a Rails book, not a Ruby book.
Ruby is the language that the Rails framework is written in, and weâll teach you just enough Ruby as we go along. Donât worryâif you have some experience of another programming language like C# or Java, youâll do just fine. Rails is such a powerful system that you can get a very long way with just a little Ruby knowledge.
The activities are NOT optional.
The exercises and activities are not add-ons; theyâre part of the core content of the book. Some of them are to help with memory, some are for understanding, and some will help you apply what youâve learned. Donât skip the exercises.
The redundancy is intentional and important.
One distinct difference in a Head First book is that we want you to really get it. And we want you to finish the book remembering what youâve learned. Most reference books donât have retention and recall as a goal, but this book is about learning, so youâll see some of the same concepts come up more than once.
We donât show all the code all the time.
Our readers tell us that itâs frustrating to wade through 10 slightly different versions of the same piece of code, so sometimes we will only show the parts of a script that have changed.
The chapters are skills-based not technology-based.
Each chapter will give you the skills to write more and more advanced and valuable applications. So we donât have chapters that just deal with talking to databases or designing a pretty interface. Instead, every chapter teaches you a little about the database, a little about the interface, and a little about several other parts of Rails. By the end of each one, youâll be able to say, âCoolânow I can build apps that can do X.â
The technical review team
Andrew Bryan is a software development and business consultant from Auckland, New Zealand. He is currently working for an online media and advertising company in Boston, where he lives with his lovely wife Angie.
Jeremy Durham has been building web applications using Ruby on Rails since early 2005, and has contributed to several Ruby libraries. He lives in Arlington, Massachusetts with his wife and two children.
Matt Harrington is a Northeastern University alumni and has been an avid programmer since age 9.
Mike Isman has been working with Ruby on Rails since he joined the eons.com team early in 2006, before Rails 1.0 was released. While working at Eons, Mike has also written smaller sites in Rails including the Life Expectancy Calculator at livingto100.com. He graduated in 2004 with a degree in Computer Science from the University of Rochester and has been busy doing web development ever since.
LuAnn Mazza is a Computer Analyst from Illinois.
Eamon Walshe is an Agile Coach with Exoftware and a former Distinguished Engineer with IONA Technologies. He is a fan of Rails because it allows developers to concentrate on what mattersâdelivering real business value, quickly.
I owe a huge debt of gratitude to my editors, Brett McLaughlin and Lou Barr. They were always available for advice and support and whenever I came across a problem that seemed completely insoluble, they were not only able to identify exactly what was wrong, but why it was wrong and then come up with several ways of fixing it.
I owe a very particular thank you to my wife, the author of Head First Statistics, Dawn Griffiths. This book would simply not have been completed on time had it not been for the immense amount of work she did on the final version.
This book is every bit as much hers as mine.
The OâReilly team:
To Caitrin McCullough and Karen Shaner, who kept track of everything from contracts to web content.
To Brittany Smith, the bookâs Production Editor, for being a powerhouse of practical support.
To Catherine Nolan, for patiently guiding me through the first phase of the book.
To Laurie Petrycki, for her faith in the book and for allowing me to use her office in Cambridge.
And to Kathy Sierra and Bert Bates, the creators of the Head First Series, whose original vision has transformed the way technical books are written.
And not forgetting:
Brian Hanly, the CEO at Exoftware, and Steve Harvey. Their unstinting support and kindness made this book possible.
And finally the entire technical review team who had to perform an amazing amount of work in a very small amount of time.
I owe you all more than I can ever repay.
SafariÂ® Books Online
When you see a SafariÂ® icon on the cover of your favorite technology book that means the book is available online through the OâReilly Network Safari Bookshelf.
Safari offers a solution thatâs better than e-books. Itâs a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at