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.
Sounds better than most "recipe" books (Score:3, Insightful)
Must Every Submission Read Like a Marketing Slogan (Score:1)
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
Re:Must Every Submission Read Like a Marketing Slo (Score:2, Funny)
No kidding! I can't think of the last book review I read that didn't mention some sort of product for sale, usually a book!
Johnny Come Lately Books (Score:3, Interesting)
Re: (Score:2)
That's incorrect. The book seller/publisher/author pay for it, with decreased profits. You apparently think the bookseller goes like "Oh, these leeches who return books eat into my profits, so I'll have to increase my book prices to make up for it." But if a book seller could increase profits simply by increasing prices, they would do so anyway, they wouldn't need the leeches as an excuse. By increasing their prices the
Re: (Score:2)
Re:Johnny Come Lately Books (Score:5, Funny)
James' Books (Score:3, Interesting)
rail recipes, :( (Score:1, Funny)
No current or nail ammo
No trigger or sight
(: Haiku
This shouldn't be your first Rails review, either (Score:5, Interesting)
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.
Re:This shouldn't be your first Rails review, eith (Score:1)
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)
Hope this helps.
Re: (Score:3, Insightful)
Acts as Taggable
Acts as Versioned
low-flash coding
DRYing up your code
routing methods
Re:a glossary (Score:5, Informative)
Re: (Score:2)
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)
Re: (Score:2)
I guess I should feel reassured that it never occurred to me to use the flash that way.
+1 That applies to any language (Score:2)
Re: (Score:2)
Re:This shouldn't be your first Rails review, ... (Score:2, Interesting)
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
Re: (Score:2)
I'm not exactly a Ruby guru, but let me try:
How is this possible? (Score:5, Funny)
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)
I conclude the reviewer lacks basic literacy or vocabulary skills. Literally.
I further conclude that the reviewer was REALLY hungry.
Re: (Score:2)
Re: (Score:2)
You keep using that word... (Score:2, Informative)
I do not think it means what you think it means.
Sincerely
-Inigo Montoya
Re:You keep using that word... (Score:5, Funny)
Re: (Score:1)
Well, it's subjective based on reading your link AC, but all I got out of that was:
Thanks for the link- I was going for a P.B. quote above and beyond being a over-correcting jerk :)
Equivalent framework for Python (Score:5, 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 [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)
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,
Re: (Score:2)
But that's exactly what PHP requires!
True enough. Django and RoR aren't for people who only have cheapo shared web hosting plans.
They've had instructions [djangoproject.com] since forever. It does require some meddling with the Apache config, but it's not too
... Ack. :) (Score:2)
> 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
Re: (Score:2)
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
versus deploying to Tomcat (Score:1)
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.
Re: (Score:1)
Re: (Score:2)
Re: (Score:2, Insightful)
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
Struggling to Learn Rails (Score:1)
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
Re: (Score:2)
Nice way to learn, and get a name out there for yourself.
Re: (Score:1)
One recipe this book doesn't cover (Score:2)
The SQL statement was generated by iterating over the categories checkboxes fr
Re: (Score:1)
Re: (Score:1)
Some plugin recommendations (Score:2)
Re: (Score:2)
Buying the PDF? (Score:1)
Re: (Score:2)
Re: (Score:1)
I wonder why the original poster linked to B&N, rather than directly there?
Re: (Score:2, Informative)
Ruby on Rails (Score:1)
It's nice for little things. (Score:3, Informative)
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.
Re: (Score:1, Redundant)
Re: (Score:3, Insightful)
> good idea for really large projects either.
Hm, I think if you're doing a large site - e.g., multiple app servers - the speed at which the language's opcodes are processed won't be the bottleneck. It'll be database queries or the network connections or something like that.
Anyhow, it's working pretty well for us so far [getindi.com]...
Our datacenter uses clustering and vertical scalin (Score:2)
I suppose in a traditional environment you'd just throw more servers at it, but I've never like that idea. The administrative costs in a high-avail datacenter are not to be sneezed at!
Re:Our datacenter uses clustering and vertical sca (Score:2)
> each app is given a classification which determines how
> important it is. CPU is at a premium in this environment,
Really? I mean, sure, you don't want something to get caught in a tight loop and burn up cycles, but is the difference between a Ruby app and a Java app really that much? Anything involving bit-shifting or really dense math can be rewritten in C... I guess I just don't see the problem.
> The administrative costs in a high-ava
Re: (Score:2)
You start coding a web app you need, 3 DB tables. You normalize the db and add couple things you didn't think about in advance, 10 tables. Oh, login and permission data, at least other three. At least three web templates.
Barely one man month after, your app is mature beta and you already gained from having started with MVC. I'd add, if your code has not implemented at least some MVC-like separation you are already swimming in spaghetti.
In soviet PHP lan
Re:It's nice for little things. (Score:4, Interesting)
Admittedly, Rails debugging tools cannot compare to those of
As a side note, there are some frameworks in PHP now that can compare to the Rails way of doing things (like CakePHP or Symphony). I still prefer Ruby as a language, but those frameworks seem pretty decent. However, I don't think you can compare pure vanilla PHP to Rails.
-Aamer
Re: (Score:2)
"Premature optimization is the root of all evil (or at least most of it) in programming."
-Donald Knuth
Re: (Score:3, Insightful)
Well I'd counter with "thinking you can always optimize later is the root of Open Office"
Re:It's nice for little things. (Score:5, Interesting)
Re: (Score:2)
Firstly, those companies don't do everything in those languages - there is a lot of integration with other frameworks. Secondly, using that approach is fine if you have the resources of those companies. For the typical developer it is a mess. Thirdly, note how MySpace is moving to
Re:It's nice for little things. (Score:4, Informative)
Single web page? That isn't a small project... that is a TINY project.
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.
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.
You fail to see the huge space between PHP and Java.
-matthew
Re: (Score:2)
Or a tiddly [tiddlywiki.com] one!
Re: (Score:1)
Yes for a single Web Page thing, you don't need rails, but for a single Web Page thing, you probably don't need PHP either. You probably need just HTML. Or is it that, "single Web Page thing" you are talking about is not single at all. Well then... "Because it's not compiled, it seems like it's not a good idea for really large projects either."
Which Web P
Re: (Score:2)
Re: (Score:1)
Re: (Score:1)
Simple: People who have in the past, been forced to fight with, or pay programmers, or use off-the-shelf webapp products, are
simply doing it themselves. Rails enables this. While programmers are bitching amongnst themselves about whether Ruby is an inferior language, or whether Rails is an incomplete or inefficient framework, or whether it's going to "win" against Java and
Re: (Score:2)
Re: (Score:1)
I have witnessed this, and it has made me very afraid.
I do not get the impression that many people understand what Rails (not necessarily Ruby), represents.
Programmers think in the context of adopting yet another platform. They miss the point. A technology like Rails threatens to make "programmers" obsolete, at least in certain seg
Re: (Score:2)
I feel as threatened by Rails making me obsolete, as I do feel threatened by Lego Logo.
People who were never able to write programs in, say, CGI, PHP, or servlets/JSP, are writing Rails apps without much difficulty.
Thanks for the propaganda, but I'd like to see actual examples to acknowledge this as anything other than completley disconnected from reality BS.
It's a lot ea
Re: (Score:2)
Oh, it's *opinionated*, certainly.
It does NOT appreciate you trying to do anything but a Web2.0 app, with forward generation of a db schema on MySQL. It absolutely, positively despises you trying to use an existing db schema, or to interoperate with anything resembling a J2EE app.
However, if you are willing to play by its rules, it rewards the novice. I say "Rails", and not "RoR" and not "Ruby", because I consider "Rails" to be an entirely distinct idiom from Ruby. Ruby is a language for Computer Scientists
Re: (Score:2)
Re: (Score:2)
Actually the "$name" is optional, PHP classes know very well what they are named.
Re: (Score:2)
Re: (Score:2)
PHP has the same so you can make a class "visible" as string, iterator etc.
Optional parenthesis: "has_many(:colors)" is equivalent to "has_many
Uhmm.. I'm missing your point here. Does optional parens make a huge difference in your life a
Re: (Score:2)
Re: (Score:2)
Would you agree you are more productive working on something intuitive?
Would you agree you are more productive with less redundant code?
Do you agree 1+1 = 2? Now, does this mean PHP is better? You're asking the wrong questions.
In my eye Ruby fails on all of those. Cleaner code doesn't mean randomly dropping various characters and claiming them redundant.
Unlike Ruby, PHP doesn't have hard time differentiating function from a non-function, an
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
In fact one of the cases I've looked into was penny arcade, which after switching to Rails were plagued by performance issues.
And with Rails, I don't need an IDE. For a while, I developed in vi.
You know that basically says it all. You develop in vi. How marvelous. You can develop anything in vi, but when your project grows and you work in a team, you suddenly appreciate the myriad of (probably irrelevant for you) features that makes your life easier:
- integratio
Re: (Score:2)
Re: (Score:2)
This, just like everything you said is a bunch of unsubstantiated assumptions you spew left and right in attempt to hit a weak spot.
I don't expect different from a Rails fan. You're all blind.
Re: (Score:2)
Re: (Score:2)
No offense, but I'd be drawn to any alternative just to get off of PHP...
Re: (Score:3, Interesting)
Re: (Score:2)
Those two sentences seem very contradictory to me. As the old saying goes, If you want quick, stable, and cheap, you can only pick two. Although I think that rapid application development has it's uses, it's not what I envision as a software engineering solution. I've used .Net more than anything else, and I usually steer clear from all the drag and drop user interface s
Re: (Score:2)
But a serious, multi-site web-based application that spans continents is going to require something a bit more robust.
Is Rails unstable in your experience? Two phase commits are still not implemented in rails IIRC but clustering is possible and done by rails hosting services. Just put session data on the DB so that each request sent to a rails app can be routed arbitrarily to whatever app server is available at the moment.
I use ROR + postgres on two different platforms, ppc and intel, without a hitch. Didn't try clustering the two yet.
Re: (Score:1)
Rails schmails (Score:1, Funny)
Re: (Score:2, Insightful)
The development time on the other hand is amazingly short. You can go from zero to app in times you would only dream of coming from a PHP or Java world. I personally can only vouch for PHP, but there's plenty of Java people out there who will tell you the sam
Re: (Score:1)
Re: (Score:2)
Re: (Score:2)
Absolutely. It is not so much a matter of Groovy, as the underlying framework. The framework underneath Grails is a combination of Spring and Hibernate, which are very high performance.
Re: (Score:2)
I am puzzled as to why you say this. It is common practise in Ruby to drop through to C or C++ to improve speed. In Grails, you aren't just dropping through to Java - 99% of the framework is Java, and Java which is fast and scalable, and highly tunable in ways that Rails simply isn't.
You've made the bold clame that Grails is faster than Rails, so show us the bold proof (benchm
Re: (Score:2)
Firstly, Groovy simply isn't 5x slower than Ruby. Secondly, you are wrong - Grails is not based just on the Groovy language. It is based on Groovy scripting above Spring and Hiberna
Re: (Score:2)
No, it isn't. It is only suited for the smallest and simplest of queries. Anything more than a few tables and you end up with joins, large transactions and so on.
As for complex joins, it's always better to make them on the DB side.
No, it isn't. You lose portability. You also lose the ability of the ORM to opimise such things. This kind of justification of Rails' failings is ty
You were right (Score:2)
Yes, I have to concede you are right here. I am not impressed with the Language Shootout in general, but having looked
This is my mistake - I was remembering a report on dynamic languages on the JVM, and I remembered wrong - it was the 'Nice' language that showed good performance, not Groovy.
However, I am still not convinced that Rails is generally faster than Grails, because, as I said, Groovy is only a thin layer over an ORM which is well known for good performanc
Re: (Score:2)
It is a great way to get things started, but has limited usefulness. It is intended primarily for 'greenfield' databases where you get to define everything, however a substantial fraction of database work involves connecting to existing databases, where the structures don't match the requirements of Rails. Also, defining a data model in what is supposed to be an OOP language in terms of relational database tables is..... just crap! Developers in other languages have moved
Re: (Score:2)
Not all ORM tools are like Hibernate
I use JDO (Kodo) and it really doesn't care what your object model is like - and can persist and retrieve objects from a range of stores, not just relational. These include XML, CSV, LDAP and so on.
Re: (Score:2)
Was it a long rail of brown ones of twos?