Learn Ruby on Rails

commit

push

git push origin master

git push

git push

Crafting Rails 4 Applications

The Big Picture

After the last two books on Ruby on Rails that I read, I was going to move on to filling other holes in my understanding of programming. I planned to next read either something about refactoring or test driven development or agile practices in general. But then I got an answer to my request for a more textbook-style Rails book from Daniel Kehoe. He suggested I give histutorial a try. While I don't think it addresses exactly what I was looking for, I do think it was a good book that meets the needs of novice programmers that would find tutorials likea bit too challenging.To find something to pair up with this book for beginners, I went in the other direction and picked a much more advanced Rails book with. This book goes deep into the guts of Rails, explaining code samples directly from the source code and showing how to create plug-ins, engines, and rack applications. It should offer a stark contrast toand bring out the strengths and weaknesses of both books, so let's take a look at them.Unlike most other software development books, Learn Ruby on Rails is part of an online subscription available at railsapps.github.io . If you subscribe, you get access to two books, the other one being, and a number of tutorials and guides. Starter apps and an app generator called Rails Composer are also available at GitHub. I didn't look into any of this extra stuff since I already have quite a few starter apps now from the various tutorials I've gone through. If you're curious, I encourage you to check them out for yourself.I would placeas easier than either of the other two tutorials I went through:andKehoe gives the reader a very gentle introduction to Rails with this tutorial, and keeps the book as short as he can by referring to online articles for installation instructions of Rails and other necessary tools and for more in-depth explanations of various topics.He also limits the tutorial to the controller and view sections of Rails and leaves out the use of databases entirely. For an introductory tutorial like this, I think it was the right decision. You can still make a decent Rails application without a database, and beginners can focus on understanding the view and controller side of a web application.I had a somewhat difficult time evaluating this book as an introductory text because I had already read two books on Rails, and essentially nothing was new to me. I can't know for sure how the book would work for someone who had no previous exposure to Rails, but Kehoe certainly did a good job explaining the fundamental areas of development with Rails in a clear, direct way. He started off with an overview and introduction to web development, gave a rundown of available resources, presented agile development processes, and went through how to get up and running with Ruby, Rails, rvm, gems, and Git.Once the environment was set up and the stage was set, he presented a series of exercises that built up a simple web application with home, about, and contact pages, a couple of forms with validation, and the capability of sending email. Nothing too fancy, but it gives the reader a firm foundation to build on.Sometimes things were redundant, and chapters would overlap, explaining similar material. As an example, the Gitandcommands were explained multiple times with increasing detail each time. First, Git was described in a fair amount of detail in its own chapter where it was mentioned that the commandcould be shortened toafter the first use.Then, at the end of the next chapter theshortcut was brought up again in more detail. Some issues that may have come up when using the shortened command were addressed here, but would have probably been more useful when the shortcut was introduced. I'm not sure why these explanations were split into separate chapters. Maybe it's easier for beginners to pick up more advanced features if they are introduced gradually, but I thought it was a little weird.There were two things that I really liked about this book. First, Kehoe explores the Rails framework through experimentation, which is a great learning tool. He encourages playing around with the code, and iterates through a number of ways to accomplish what's being implemented. It's incredibly valuable for programmers to get comfortable experimenting with code, learning for themselves what works and what doesn't, and gaining the confidence that the answer is there to be discovered by those that are persistent.does a good job developing those skills.Second, Kehoe forgoes the generators and scaffolding, and instead has the reader create every file from scratch. This teaching method reminded me particularly of Charles Petzold'sseries of books where he refuses to use Visual Studio's code generation features to write Windows applications. The idea is that the beginning programmer is going to learn much more by writing all the code themselves and understanding what's actually going on. Progress may be slower initially, but the foundation will be much stronger for building on later. I completely agree with that approach, and it was nice to see it inHaving Rails presented this way actually cleared up some foggy ideas and misconceptions I had about the view and controller interactions. It was very helpful, and for that alone I would recommend this book. It's fairly short and easy to work through, making it a good introductory tutorial before you move on to the more advanced ones.At the other end of the learning spectrum lies. This is a book firmly directed towards intermediate to advanced Rails developers. It assumes you have a working Rails environment and you know what to do with it. José Valim dispenses with any and all introductory material, and after a short preface, he jumps straight into the first Rails plug-in - a custom view renderer for generating PDFs from embedded Ruby templates.Code examples note which file the code should be added to, but do not show the context around the code, so you have to know where to add it yourself. Basic hand-holding is kept to a minimum so time can be spent going through the plug-ins and Rails source code while keeping the book short. There wasn't even an explanation of how to wrap a plug-in up as a gem and use it in other Rails apps. Luckily, a Step-by-Step Guide to Building Your First Ruby Gem showed up on Hacker News while I was in the middle of this book, so the solution to that problem came right to me. Talk about serendipity.The setup of the book worked pretty well, in spite of the lack of guidance for anything not directly related to building the plug-ins. For the target audience, this format was probably appropriate, and I actually got a kick out of overcoming some of the challenges I would run into as I was implementing each of the eight plug-ins. I probably made it harder on myself by doing everything in Windows 7, (I know, I know, but I don't have the money to get a MacBook, and I haven't had the time to set up Ubuntu) and things got especially hairy when I needed to install things like OpenSSL, MongoDB, and Redis to complete the later chapters.I got everything working in the end, and I was even pleasantly surprised that everything I needed was actually available for Windows 7, if I was willing to dig a little. It would be nice to have something like rvm, though. That's still missing as far as I can tell.Anyway, back to the book. These are advanced topics that Valim covers. He explains how to hook into Rails to add features and extend functionality in the rendering engine, the controllers, the HTTP responder, and the database interface. It was extremely cool to implement plug-ins that could fetch view templates from a database instead of the filesystem, send multipart emails generated from Markdown templates, stream events to clients for continuous updates to web apps, and monitor website metrics with an attached MongoDB database.Some of this stuff is over my head at this point, but when I get deeper into Rails development, I'll know where to look to find answers to questions I have about Rails internals. Even though I didn't understand everything, going through the examples was a blast, and I learned a ton of stuff about how Rails works under the hood. If you're looking for a book to take your Rails development to the next level,will help get you there.Now that I've read four Rails books, what would I recommend? Well, of the two books in this review, the choice is easy. If you're an absolute beginner with Rails, thenwould be the book for you. If you already have a few Rails apps under your belt, and you want to see how flexible and extensible Rails really is, then you should take a look at. To bridge the gap between the two, eitherorwould work perfectly, giving you a full path from beginner to advanced Ruby on Rails developer.Of course, you'll need to actually write a few non-trivial Rails apps before you can claim to have finished this learning path, andwill make much more sense after you do. Have some fun with it, and no matter what level you're at with your Rails knowledge, one of these books will help you reach the next level.