Rails 3 in Action

Several months ago, I took a look at Rails 3 in Action by Ryan Bigg and Yehuda Katz. The publisher has since provided me with a copy of the first edition, and I’m pleased to say that while the eBook preview (which was missing some content) was good, the finished book is better yet.

Who this book is for

According to the authors

This book is primarily for those who are looking to begin working with the Ruby on Rails framework and who have some prior experience with Ruby, although that is not entirely necessary.

While mostly true, I would add that if you’re completely unfamiliar with web development and/or programming, this book will be a challenging read, to say the least. The book goes through building an application and all steps are quite well explained. However, if you lack said technical experience, you will have a very tough time wrapping your head around the concepts that are presented. In other words, you’d have trouble going from “the application works if I type in the code in the book” to “this is how I can apply this in my own project”.

That said, if you’ve either dabbled in rails (say, by reading a few tutorials), or are familiar with programming/web development but new to Rails (e.g. you’re an expert in .Net, but have never developed a Rails app), then this book will be the perfect match for you.

In addition, even if you are a “seasoned” Rails hacker but you never took the time to learn how to develop maintainable apps, this will be a great book for you: you’ll learn a lot and will definitely be referring back to the contents down the road.

The content

The one thing I like most about the book’s approach is that it follows a philosophy of “this is how to do things professionally”, instead of (like many other books) taking the route of “this is how you can get something up and running”. The value of the first approach is that you’ll learn to build something that will be much easier to maintain and develop/refactor going forward. I can’t tell you how many times the “professional” approach presented in the book has made my life easier when significant changes were requested in applications: using Git and Behavior-Driven Development really help you to code fearlessly.

Here’s a rundown of the table of contents:

  1. Ruby on Rails, the framework Developing a small application with scaffolding, migrations, validations, etc.
  2. Testing saves your bacon Introducing test- and behavior-driven development (with RSpec and Cucumber), and why they’re important. You can even see most of the chapter’s content here !
  3. Developing a real Rails application This is where the book starts to set itself apart: at this point, most books would start with generating the basic application functionality with scaffolds. Here, however, the reader starts by writing out a Cucumber scenario, then fleshing out the functionality to make the tests pass.
  4. Oh CRUD! Implementing CRUD functionality and introducing Factory Girl along the way.
  5. Nested resources Implementing nested resources.
  6. Authentication and basic authorization Implement authentication with Devise.
  7. Basic access control Limiting some actions to admins only, and using namespaces.
  8. More authorization Implement access control using a Permission model, using CanCan to manage authorization., assigning permissions to users.
  9. File uploading Attaching files in the application, using jQuery to add upload fields with AJAX, serving files through a controller (so they can’t be accessed by entering the filepath and bypassing your application).
  10. Tracking state Adding functionality to the book’s app, where the authors cover using callbacks and  the ‘show me the page’ step in Cucumber, among others.
  11. Tagging Implementing tagging functionality within the app, with deleting tags via AJAX.
  12. Sending email Using observers to track model changes, using Action Mailer to email users (including HTML emails), reading email on Gmail with the gmail gem, manipulating your application (updating models) based on email replies.
  13. Designing an API As the title indicates, this chapter covers designing an API for your app, including more advanced concepts like rate limiting queries and how to version you API.
  14. Deployment Deploying your app using VirtualBox and Vagrant. Covers setting up the server (installing RVM, a database, nginx and Passenger, configuring an SSH tunnel), and deploying with Capistrano.
  15. Alternative authentication Implementing OAuth authentication with Twitter and Github.
  16. Basic performance enhancements Pagination, tweaking database queries, caching, background workers.
  17. Engines Explaining engines, writing your own engine (including setting up testing), releasing the engine as a gem, integrating the engine with the application.
  18. Rack-based applications Building them, re-implementing the app API and serving requests with Rack, creating Rack middleware.

Conclusion

As you can likely tell from the contents (especially the last third of the content), this is definitely not “just another Rails book”. It covers Rails 3.1 in depth with a pragmatic, “real world” approach and presents a lot of gems and tools from the Rails ecosystem that are incredibly useful.

The book’s tone is very conversational, and the application is developed by adding bite-sized features. By following along, you’ll be able to pick up valuable development reflexes (write test scenarios for your features before coding them, commit your code after each logical step, etc.) that will save you hours of frustration down the road and will yield a maintainable application: refactoring an application that has no tests will shorten your lifespan.

The only nitpickings I’d have with the book are a few minor typos/oversights here and there, and an overall lack of color which could be put to good use in highlighting code sections in a visually pleasing way. Naturally, these minor blemishes in no way reduce the book’s value and it deserves a spot on many a Rails developer’s bookshelf.

All in all, if you’re comfortable with programming and/or developing websites, this book is a great investment, and you’ll likely find yourself looking up various subjects, as it’s usually quicker to look up the step by step outline of the solution rather than racking your brain or searching online.

Last but not least, if you buy the printed edition you can download the eBook version free of charge (pdf, ePub, kindle).

This entry was posted in Rails. Bookmark the permalink.