Slashdot Mirror


Rails Recipes

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.

9 of 153 comments (clear)

  1. It's nice for little things. by FatSean · · Score: 2, Informative

    But a serious, multi-site web-based application that spans continents is going to require something a bit more robust.

    Since I'm always being told to build big things, I just couldn't get into Ruby/Rails.

    Maybe for a personal site or something.

    --
    Blar.
    1. Re:It's nice for little things. by misleb · · Score: 3, Informative
      If your building a small project, the model-view-controller thing can get really annoying, with the needing of 3 files for a single web page thing.


      Single web page? That isn't a small project... that is a TINY project.

      Because it's not compiled, it seems like it's not a good idea for really large projects either.


      So you don't see any applications somewhere between a tiny project and a large enterprise application? Seems to me that most applications fit in this area. Blogs, forums, CMS, all kinds of things. An intranet is a great place for rails apps.

      I really couldn't find any reason why I'd want to use it above PHP,


      For one thing, PHP is an ugly language with a hacked together object system and terrible function naming. Ruby blows PHP away as far as scripting languages go. And then add Rail on top of it which totally takes advantage of Ruby's features.

      I did PHP for a while, but after writing an app in Rails for first time, I didn't want ot touch another line of PHP again. If I need to throw some simple dynamic content on a website, I'll resort to PHP because it is so readily available, but beyond that, forget it. I won't waste my time.

      and it doesn't really have the qualities needed to take on something like Java or .Net.


      You fail to see the huge space between PHP and Java.

      -matthew
      --
      "THERE IS NO JUSTICE, THERE IS ONLY ME." -Death
  2. You keep using that word... by elcid73 · · Score: 2, Informative
    ...and had literally devoured the book in no time.

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

    Sincerely
    -Inigo Montoya

  3. Save $11.20 by buying the book at Amazon.com! by Anonymous Coward · · Score: 0, Informative

    Barnes and Noble is selling this book for $32.95, but Amazon.com is only selling it for $21.75!

    Save yourself $11.20 by buying the book here: Rails Recipes. That's a total savings of 33.99%!

  4. Equivalent framework for Python by defile · · Score: 4, Informative

    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 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.

  5. a glossary by sammy+baby · · Score: 4, Informative
    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." 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.
    1. Re:a glossary by sammy+baby · · Score: 4, Informative
      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.
    2. Re:a glossary by number6x · · Score: 3, Informative
      • 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.
  6. Re:Buying the PDF? by larry+bagina · · 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.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.