I’ve often longed for a way to render something or redirect_to somewhere and finish the action’s execution at that point. Often, I resort to something messy like this:
if cant_move render :nothing => true return end
While playing with Rails today, I realized that there’s no reason (in the world of Ruby) that this shouldn’t work instead:
return render :nothing => true if cant_move
And it does work! I don’t know what it returns (if anything), but it doesn’t matter, since Rails doesn’t do anything with it. It looks a little funny at first with the return ren... in there, and although many Rubyists aren’t a huge fans of using the return keyword, it’s necessary for an “early-out” situation like this.
Now I need to go refactor a bunch of my code…
Definitely hand-crafted and maintained by Slippy Douglas. All questions/comments may be directed to him, whether he likes it or not.
Powered by Radiant CMS, running on Rails, running on Ruby Enterprise Edition, running on Phusion Passenger, running on Apache, running on Debian Linux, running on Love.
Part of the Slippy Douglas family of sites: SlippyD.com | ClutterApp | DeliTag | R•Node.net | Nectar Games | 6BITT.com
Copyright © 2003-2009, Slippy Douglas. All rights reserved, unless otherwise specified or conflicting, in which case:
“Copyright © the-appropriate-year, the-appropriate-copyright-holder.”