Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Book Reviews Books Media

Rails Recipes 153

James Edward Gray II writes "If you have been swept up by the Rails craze or are even just a casual fan, you have probably been waiting for the terrific books to start rolling in. Some early entries, like Agile Web Development with Rails, were very solid but for me greatness arrived with Rails Recipes. For those who are not familiar with it, Rails is a full-stack web application framework, for quickly developing state-of-the-art web applications. Rails Recipes is the latest book on the subject from the Pragmatic Programmers." Read the rest of James's review.
Rails Recipes
author Recipes
pages 299
publisher The Pragmatic Programmers
rating Excellent
reviewer James Edward Gray II
ISBN 0-9776166-0-6
summary A programming cookbook for all things Rails.


Let me tell you how I discovered Rails Recipes. At the Rails shop I work for, we needed a favorites system for our latest application. When I inherited the task of implementing favorites, I had heard just enough to guess that the new polymorphic associations feature of Rails might be just what I needed. Sadly, I had never even seen an example of their usage. Before leaving work that day, I checked the table of contents to make sure a recipe for what I needed was in there and and bought a combo pack, so the PDF would be waiting for me in the morning. The next day I built the entire favorites system and integrated it into our application with only the book as my guide. Total time for implementation, from cracking the book to a complete solution: just over three hours.

Needless to say, the book had completely won me over by that point. I started sneaking in recipe reads whenever I had a free moment or two and had literally devoured the book in no time. I completely expected it to show me cute AJAX tricks and handle common issues like login code and it certainly does these things. It also covers popular plugins, including Acts as Taggable and Acts as Versioned, as it should. What I didn't expect was for the book to include so many excellent low-flash coding recommendations as well. There are terrific recipes for DRYing up your code in various circumstances, building your own output forms for views, how to use models in migrations even if the files are long gone, integration testing as a DSL, routing methods, code generation, and a whole lot more.

The book has some surprising depth to the Rails insights it provides, not because the recipes are long but more because the topics are well chosen. Even the small "Snack Recipes" generally dive right to the heart of a commonly encountered matter. You get typical solutions and often some tips on how to customize the relevant Rails behaviors. For example, the book covers how to add inflections Rails can use in its singular/plural text transformations and how to tie your own form building classes right into the standard Rails helper methods.

I'm a long time Ruby user and I consider myself fairly knowledgeable with regard to the language, but this book taught me new tricks. I've read the Pickaxe, but for some reason IRb sessions never sunk in for me until this book showed the perfect example of using the on an ActiveRecord model to create a Ruby syntax database shell. The book even taught me some great YAML tricks for use in fixtures and configuration files.

Now I realize I've been gushing a little, so let me to balance it with at least some words of caution. First, this book assumes you know Rails. You will not learn Rails here. This should not be the first Rails book you read, though it does make an ideal second read and daily reference. I should also note that the recipe sections seem pretty arbitrary to me. I expected to find the login discussion in the "Big-Picture Recipes" section and the console tips in "Database Recipes", but they are located elsewhere. This might be a minor challenge for those who try to thumb straight to a recipe, but I've found searching the PDF makes this a non-issue. (The paper version of the book does have nice tabs drawn on the edge of pages to lead you to recipe types though, unrelated to the sections.) Finally, I should note that I've gone hunting in the book for about four work projects now, and found all but one. It didn't cover Acts as Threaded usage. Obviously it is impossible for a single book to answer all your questions about Rails, but a 75% ratio seems like a great start to me!

There are 70 recipes in this book split among user interface, database, controller, testing, big-picture, and email categories. I must stress again though how well these recipes pack in the tips. Don't be at all surprised if you learn an applicable view layer or even pure Ruby trick in a database recipe.

If you are a Rails user, I must recommend you pick up this title immediately. I really believe there is something in here for all.


You can purchase Rails Recipes from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

Rails Recipes

Comments Filter:
  • by Salvance ( 1014001 ) * on Monday December 11, 2006 @02:57PM (#17198724) Homepage Journal
    I typically dislike the "recipe" books available, as most of them seem to only touch about 10% of what I'm actually interested in. However, this book sounds better, maybe this is because the projects I'd be interested in using Ruby on Rails for are far simpler than most projects I undertake.
  • If you have been swept up by the Rails craze or are even just a casual fan, you have probably been waiting for the terrific books to start rolling in.

    I used to come here to get away from this crap.

    I don't have a problem with Slashvertisement in general but come on, I can't even get past the first sentence before I wretch. At the least back in Slashvertisement's infancy people would pretend like it was an actual News for Nerds submission (remeber the They Might be Giants stories?)

    Let us have the thrill of seeing through your weak smokescreens. When you don't even make an attempt to fool us it takes the fun out of it, a kindergarten class could fi

  • by Super Dave Osbourne ( 688888 ) on Monday December 11, 2006 @03:18PM (#17199004)
    Rails has been around for a while, and the books are all pretty good (bought 5, read 5, returned 5)... The only book really worth reading to any seasoned MVC or Morphic programmer is the Getting Started with Rails... The rest are really just rehash on MVC which is so dated we should all look carefully at why Rails is so special to the masses in the first place.
  • James' Books (Score:3, Interesting)

    by Super Dave Osbourne ( 688888 ) on Monday December 11, 2006 @03:21PM (#17199058)
    James is a good guy, and knows his Mac crack. Guys has been alive and well in the community for 3 years, and is a great guy with the Ruby Quiz. Conflicting publisher (or not) his views are almost always well thought out and valid, regardless of how silly and useful the Quiz is :) Glad to see James has a TextMate book coming out with Oreilly. In all, the book itself (the Rails Recipes) is about a 7-8 out of 10 mac strokes.
  • No coils or magnets.
    No current or nail ammo
    No trigger or sight

    (: Haiku :)
  • From the review:

    Now I realize I've been gushing a little, so let me to balance it with at least some words of caution. First, this book assumes you know Rails. You will not learn Rails here.

    Actually, I could hardly read your review, since it was so crammed with non-standard jargon (at least, from my perspective as a longtime C++/Java programmer). Lighten up on the Ruby-specific buzzwords, please! "how to use models in migrations", "integration testing as a DSL", "great YAML tricks for use in fixtures", huh???? It's nice that the book taught you how to do those things, whatever they are, but maybe a review should relate these things to more normal (non-Ruby) programmers' experiences in common language somehow.

    • Well, it *isn't* an appropriate first book on Rails. By the time you have an interest in or need for this book, you should know what those terms mean. Go through the exercise of building the "depot" application in the first few chapters of Agile Web Development With Rails, and this will all make perfect sense to you.

      I bought this book at the same time that I bought Programming Ruby and Agile Web Development with Rails. I paged through Recipies, and it was all Greek to me. I set it aside, having seen enough,
    • a glossary (Score:5, Informative)

      by sammy baby ( 14909 ) on Monday December 11, 2006 @04:32PM (#17200072) Journal
      To address your specific areas of confusion:
      • "How to use models in migrations" - Rails uses the "Model-View-Controller" structure for application architecture. It also offers scripts which automate the creation of new models: basically, you type "script/generate model modelname", and it drops in files for model code, unit tests, et cetera. Rails also offers a method for making updates to your application's database schema called "migrations." Every time you generate a new model, it will also create a dummy "migration" into which you can enter the code necessary to update your database, regardless of the specific type of database you're running (Informix, MySQL, Oracle, Postgres...).
      • "Integration testing as a DSL" - In Rails parlance, an "integration test" is a test which spans multiple models, controllers, and views. DSL, or "Domain Specific Langage," is a buzzword which basically means "a language specifically tailored to a certain task." It refers to the phenomenon some that Rails code, especially the integration test code, doesn't really scream "I am a Ruby program" to you - the method calls have evolved to the point where they look like a whole new language perfectly suited for a specific task. (That's the claim, anyhoo.)
      • "Great YAML tricks for use in fixtures - YAML stands for "YAML Ain't Markup Language [yaml.org]." It's a very simple way of representing data structures in text. Rails uses YAML for unit test fixtures: that is, your testing database can be populated with information from YAML files. Interestingly, the test fixtures can have Ruby code embedded directly in the YAML, enabling you to do stuff like iterate over hundreds of similar items. The embedded Ruby code is what makes the "great YAML tricks" possible.


      Hope this helps.
      • Re: (Score:3, Insightful)

        Thanks, now please explain:

        Acts as Taggable
        Acts as Versioned
        low-flash coding
        DRYing up your code
        routing methods
        • Re:a glossary (Score:5, Informative)

          by sammy baby ( 14909 ) on Monday December 11, 2006 @08:21PM (#17202678) Journal
          My pleasure.

          • acts_as_taggable
          • Acts as Versioned - see above, but allows you to have multi-versioned objects, instead of tags.
          • DRYing up your code - slang. DRY stands for "Don't Repeat Yourself." DRYing up your code, therefore, is making sure that you haven't duplicated code unnecessarily.
          • routing methods - methods that govern how a Rails application will choose a controller and method based on a URL. The "default route" in most Rails applications is "controller/method/id", meaning if I were to submit a GET request for "http://railsthingy.net/photos/view/101", the application would attempt to call the "view" method from the "photos" controller, with an argument "id=101".
          • low-flash-coding - this... um. Well. You got me, dude.
          • Doh! Slashdot done ate my lovely explanation of acts_as_taggable.

            In short: "acts_as" calls inform the Rails application that a model should inherit additional functionality from a plugin. The "acts_as_taggable" plugin bolts on the ability to assign arbitrary tags to an object - think Flickr, del.icio.us, or even Slashdot these days. Technically, I believe that acts_as_x uses mixins to work their magic: a mixin is Ruby's version of a Java "interface," basically a way to inherit functionality from multiple s
          • Re:a glossary (Score:4, Informative)

            by number6x ( 626555 ) on Monday December 11, 2006 @11:04PM (#17203778)
            • low-flash coding - The 'flash' is a small area that keeps things around until the next transaction. You should use it just to pass error messages from a failure of some type. Some programmers try to get tricky and use the flash as a psuedo session. Rails supports sessions fully and you should use the session for your needs. Getting tricky is usually a sign you don't really know what your doing in Rails.
    • Lighten up on the Ruby-specific buzzwords, please! "how to use models in migrations", "integration testing as a DSL", "great YAML tricks for use in fixtures", huh???? It's nice that the book taught you how to do those things, whatever they are, but maybe a review should relate these things to more normal (non-Ruby) programmers

      Most of those _are_ 'normal' terms.

      Models are a fundamental part of the MVC [wikipedia.org] design pattern (which originated in 1979 [ifi.uio.no], so it isn't exactly a rails buzzword!), integration testing [wikipedia.org] is part of general software testing, usually used in combination with unit testing, and YAML [wikipedia.org] is a markup language (sort of). They aren't Ruby or Rails specific.

      Don't assume you know all the 'normal' terms simply because you don't consider yourself a newby. You sound like one of those programers who think they know it all... bo

    • I'm not exactly a Ruby guru, but let me try:

      models
      refers to models in a model-view-controller framework. Every decent application developer should be at least on nodding term with this
      migrations
      This is the ruby language for describing and versioning databases (both structure and data). Not too different from Java's hibernate, though Ruby makes it somewhat more elegant.
      YAML
      Yet Another Metalanguage. Think of it as another XML (but not quite as unreadable.) It was never really meant for an XML replacem
  • by Anonymous Coward on Monday December 11, 2006 @03:34PM (#17199236)
    From the review:
    I started sneaking in recipe reads whenever I had a free moment or two and had literally devoured the book in no time.

    Okay, so what he's saying is he literally ate the book and, moreover, he ate the book in literally 0.000 seconds.

    I conclude the reviewer lacks basic literacy or vocabulary skills. Literally.
    • Re: (Score:2, Funny)

      by Anonymous Coward
      Okay, so what he's saying is he literally ate the book and, moreover, he ate the book in literally 0.000 seconds.

      I conclude the reviewer lacks basic literacy or vocabulary skills. Literally.


      I further conclude that the reviewer was REALLY hungry.

    • No, no, no. He didn't mean "literal" in the literal sense.
    • by aclarke ( 307017 )
      I think he needs to learn that you're not supposed to actually EAT the recipe book. Sometimes the difference between an object and its subject can be confusing, I suppose.
  • ...and had literally devoured the book in no time.

    I do not think it means what you think it means.

    Sincerely
    -Inigo Montoya

  • by defile ( 1059 ) on Monday December 11, 2006 @04:18PM (#17199882) Homepage Journal

    Since I'm already familiar with Python and use it on a daily basis, my experience with Ruby has been pretty limited. This puts Ruby on Rails just out of my reach for a new project.

    Thankfully, there's I guess what you'd call a rough equivalent, Django [djangoproject.com] which is the first framework I've ever used that hasn't frustrated the hell out of me.

    You've got no excuses left, check it out.

    • Re: (Score:3, Interesting)

      by dankelley ( 573611 )

      Well, there is an excuse left, if you're a PHP programmer looking for a replacement (be that django or rails) -- it's the issue of how to deploy the sucker.

      I might be like some others reading this thread. I'm familiar with PHP and I'd like to switch up to something more elegant.

      But there's a roadblock when it comes to deployment.

      With PHP, it's simple -- your test machine is probably set up already, and your deployment webserver almost certainly is. With Rails and Django, you're in a spot of trouble,

      • It's not trivial to just install "mod" modules to get Rails and Django to work

        But that's exactly what PHP requires!

        and you have to own root permissions to do that.

        True enough. Django and RoR aren't for people who only have cheapo shared web hosting plans.

        I'd sure love to see the folks who are writing the Django book drop whatever chapter they are writing and move on to the deployment chapter.

        They've had instructions [djangoproject.com] since forever. It does require some meddling with the Apache config, but it's not too

      • Okay, I generally try not to make snarky comments, but, with my apologies, please allow me to indulge briefly. :)

        > With PHP, it's simple -- your test machine is probably set up already, and your deployment
        > webserver almost certainly is.

        <snark>Are you FUCKING kidding me?</snark>

        (Golly, I already feel better.) :)

        Now please allow me to expand.

        Deploying for PHP is an insane pain in the ass. PHP breaks compatibility at every turn on the wind (fun fact: the product I'm paid to deploy for a larg
        • Thanks for the comment. It was very informative. I am, in fact, looking into both Rails and Django. I just wish I didn't have to install things (on my own machine) or beg the sysadmin to install things (on a deployment machine) to make test sites.

          In case it's of interest to anyone on the thread, e.g. in case it might inspire an informative comment such as the one to which I am now replying, my preference so far is for Django, partly because I like the "feel" of python, and partly because I like the wa

        • God%^%2 f-!^$=ing mother-#$@#^@#2!!!

          Where in HELL is Tomcat looking for THIS class file NOW?!?#

          Mother-f@#$# s$@t-eating piss-ant mother@#!$@#$@

          Sorry, the pills haven't kicked in yet to help me get over my last week with this thing.

          God$%@!@#2 sucking @#$!*^##!......

          FRRRRAAAAAAAAAAKKKKKKK!

          Okay, feeling a bit better now.
    • Ob: The Django ate my baby.
    • Comment removed based on user account deletion
    • Re: (Score:2, Insightful)

      by fishbowl ( 7759 )
      >This puts Ruby on Rails just out of my reach for a new project.

      Here is the thing you should realize: There are people out there who have never written a line of code in any language,
      who have picked up Rails and put together a webapp on day one. Within a few hours of the first tutorial.

      Lots of people who do graphics and layout, who have historically needed someone else to do the programming for them,
      seem to have discovered Rails -- and are using it rather successfully.

      I have seen this phenomenon with m
  • I bought and have skimmed the book. It seems pretty good but bottom line the problem for me isn't so much needing more books but rather a project to work on.

    If anyone's interested I've started a screencast [coderpath.com] to record my commitment to finally learn Rails. It's a pair-programming session where I invite people more knowledgeable than myself to come alongside to offer advice and answer questions.

    My first guest was none other than David Heinemeier Hansson himself. [coderpath.com]. I've also asked Amy Hoy and Geoffrey Gros
  • A couple months ago I needed to search for a list of members that fit into all categories checked by users on a web form. Rails recipes was one of several books that I looked to for a pre-packaged solution, but none seemed to cover complex has_and_belongs_to_many queries where multiple criteria must be met. Ultimately I had to use custom SQL, but being not all the familiar with rails/activerecord I wonder if there is a better way.

    The SQL statement was generated by iterating over the categories checkboxes fr
    • Well, if you're bound to Ruby, I don't know where to start. However, Perl's Class::DBI can do a lot of this type of code generation for you, including the many-to-many references. Combined with something like CGI::Application, you can create a powerful website with very little fuss.
      • Catalyst (the elegant MVC framework) is written by many of the same people who work on Class::DBI. It used to integrate very nicely, but CDBI has been deprecated in favor of DBIx::Class (also written by the Catalyst core, iirc), which is mostly backwards compatible with CDBI but adds a lot of new code generation facilities.
    • I would look at squirrel [thoughtbot.com] and ez_where [brainspl.at] -- I am not sure if these implement what you're looking for but they're the two plugins I know that can make complicated searching simple.
    • Comment removed based on user account deletion
  • Okay, I give up ... how do I buy the PDF? I've had a look on B&N but apparently they don't sell eBooks any more.
    • by booch ( 4157 )
      The book is published by The Pragmatic Programmers [pragmaticprogrammer.com]. You can buy the Rails Recipes [pragmaticprogrammer.com] book directly from them, as well as the PDF.
      • Thank you, sir :-)

        I wonder why the original poster linked to B&N, rather than directly there?
        • Re: (Score:2, Informative)

          Slashdot has a linking agreement with barnes & noble (check the faq, under book review guidelines). BN.com might be 5-15% more expensive than amazon or bookpool, or almost anywhere else (except a physical barnes & noble), but according to VA Software's SEC 10Q reports, they get $20k/year kickback from it.
  • I am a lightweight web developer, mostly by hobby and not by trade. I have random brushes with PHP for news posting and database usage, but I found the work required to do even the simplest of things in PHP took forever to perfect because of my inexperience. I was pointed to Ruby on Rails as a 'cool language to check out' and I figured I'd give it a look. After about 12 hours of tinkering and playing around, I had a local test server, database and a small blog written in rails. Sure, it probably won't scale

In case of injury notify your superior immediately. He'll kiss it and make it better.

Working...