Coming in Rails 2.3: Simpler Rendering
Over the years,
[sourcecode language='ruby']
render :action => "edit"
render :template => "products/show"
render :file => "/u/apps/other/warning.html"
render :nothing => true
render :inline => ""
render :update {|p| p.replace_html "A", "Error!"}
render :text => "OK"
render :json => @product
render :xml => @product
render :js => "alert('error!');"
[/sourcecode]
Those options will still be in Rails 2.3, but the first three have a simpler alternative now:
[sourcecode language='ruby']
render "edit"
render "products/show"
render "/u/apps/other/warning.html"
[/sourcecode]
Rails will figure out whether you're rendering an action, template, or file, and do the right thing. In addition, if you like symbols, you can render an action via a symbol:
[sourcecode language='ruby']
render :edit
[/sourcecode]
ActionController::Base#render
has grown quite a few options:[sourcecode language='ruby']
render :action => "edit"
render :template => "products/show"
render :file => "/u/apps/other/warning.html"
render :nothing => true
render :inline => ""
render :update {|p| p.replace_html "A", "Error!"}
render :text => "OK"
render :json => @product
render :xml => @product
render :js => "alert('error!');"
[/sourcecode]
Those options will still be in Rails 2.3, but the first three have a simpler alternative now:
[sourcecode language='ruby']
render "edit"
render "products/show"
render "/u/apps/other/warning.html"
[/sourcecode]
Rails will figure out whether you're rendering an action, template, or file, and do the right thing. In addition, if you like symbols, you can render an action via a symbol:
[sourcecode language='ruby']
render :edit
[/sourcecode]
Double Shot #357
Last one of these before my tiny Christmas break.
Merb gets merged into Rails 3! and Rails and Merb Merge - The big news from yesterday is that Rails and Merb will be as one some time next year. I am guardedly optimistic; though I look forward to seeing what comes of the partnership, as someone who spends much of his time reviewing others' code I dread all the additional pieces I will need to develop expertise in.
iphone-rdoc-template - If you find yourself wanting to read ruby library docs on your iPhone, this would come in handy. Demonstration at PocketRails.
irb & script/console tips - Some useful tidbits here.
FireUnit - JavaScript unit testing extension for Firefox and FireBug.
Super Daring App Template - Peter Cooper contributes a template for the templating feature in edge Rails.
Multi-variable Initialization Gotcha
Sometimes the fact that I don't know all the ins and outs of Ruby, coupled with habits carried over from other languages, turns around to bite me. Here's a console session demonstration of the latest problem I had:
[sourcecode language='ruby']
>> a = b = 2
=> 2
>> a = 3
=> 3
>> b
=> 2
>> a = b = []
=> []
>> a << 2
=> [2]
>> b
=> [2]
>> a = []; b = []
=> []
>> a << 2
=> [2]
>> b
=> []
[/sourcecode]
So, trying to initialize multiple arrays and multiple integers doesn't work the same. Live and learn.
[sourcecode language='ruby']
>> a = b = 2
=> 2
>> a = 3
=> 3
>> b
=> 2
>> a = b = []
=> []
>> a << 2
=> [2]
>> b
=> [2]
>> a = []; b = []
=> []
>> a << 2
=> [2]
>> b
=> []
[/sourcecode]
So, trying to initialize multiple arrays and multiple integers doesn't work the same. Live and learn.
Double Shot #356
Things may finally be slowing down for Christmas on the net, though not yet in my consulting practice.
Twitter Scrape - I have no early use for gigabytes of Twitter social network statistics, but this is fascinating nonetheless.
CloudKit - "RESTful JSON storage with Optional OpenID and OAuth support." Rack middleware too. How many more buzzwords could you want?
Double Shot #355
Things may slow down a bit for the holidays...but for me, they're still cooking right along.
Model Plus - My latest Rails plugin, an enhanced model generator.
Agile git and the story branch pattern - Josh Susser discusses how to work with git effectively.
Read The Source, Luke: A Reader’s Guide To Browsing Rails Source - Yes, the Rails source is worth digging into to improve your own skills and understanding of Rails.
Easy Dependency Management for Git with Braid - Techniques worth knowing about. I'm still waffling about how to handle these things in my own projects.
cinabox - Dead-simple setup for a continuous integration server using cc.rb.
Canticore - A new look at blogging engines. - Using RubyGems for plugins and themes.
Migrating project websites to github pages with sake tasks, new websites with jekyll_generator - More very cool stuff from Dr. Nic.
LiteFixtures - Some more syntactic sugar for Rails fixtures.
Double Shot #354
QA and documentation are on my mind this morning. I need to remember the lesson that a PM can't spend all their time coding.
Well Wishes $2 You - This doesn't really have anything to do with Rails, except that the Rails community is traditionally very giving. But if you can spare two bucks around Christmas time, you can help do some good.
Named Scope: To Lambda or Not To Lambda, That Is The Question - Good explanation of what lambdas are doing in named scopes and why you might want one.
GitHub Pages - One more spiffy feature from the GitHub folks - free hosting, essentially. It works, too.
Ruby 1.9 can check your indentation - Well, at least if you run with warnings, it can.
Amazon SimpleDB - Now With Select - A syntax change makes this cloud database more accessible for more developers.
Double Shot #353
Spent part of yesterday learning more than I really want to know about Apache logging. Perhaps I should raise our eldest to be a sysadmin.
The Fork Queue - GitHub adds another very cool feature (though with an unfortunate name).
dailygoals - A little something I'm trying out on Twitter to help keep myself on track and accountable.
Apache Logging via ServerAlias - I needed this yesterday: 10 different URLs aliased to the same Rails site, but needing separate logging & analytics.
Introducing Rack Metal - Rails now has a very fast alternative to the full stack when you need to service something at speed, or show off meaningless statistics.
Double Shot #352
Bumped my OS X up to the latest 10.5.6 yesterday...it was *mostly* smooth.
find_mass_assignment - A more sophisticated approach to finding unprotected mass assignment vulnerabilities than my little rake task.
Rails TakeFive - A Conversation with Gregg Pollack - Gregg is, as always, worth reading.
Hoptoad Gets Paid Accounts and SSL - A service I've found quite useful is tweaking its long-term sustainability a bit.
GPGMail - If you're using this PGP plugin for Apple's mail.app, you need to upgrade to the current beta for it to work on the just-released OS X 10.5.6.
Double Shot #351
Off to a new week, packed with promise...and deadlines...
Tortoisegit - Porting TortoiseSVN to git for Windows users. Looks like it's making good progress.
ProtoFX a new effect engine for Prototype - A new alternative to script.aculo.us.
Tweet Congress - Rails app that helps you find your congresscritters on Twitter, or pressure them to get on if they're not.
Launching Ruby on Rails projects, a checklist - Some good advice from Robby Russell.
Auditing for attr_accessible
By now, you all know that you need to use attr_accessible to protect your application from having any old Active Record attribute changed by a malicious user. I find myself, in the course of consulting, looking at a great number of existing applications, and I've grown tired of having to open up every model and look. So, let's be a bit smart: here's a rake task that you can drop in any existing application to do the audit for you:
[sourcecode language='ruby']
namespace :utility do
desc 'Find models that are not using attr_accessible'
task :audit_attr_accessible => :environment do
all_models = Dir.glob(
File.join(Rails.root, 'app', 'models', '*.rb')
).map{|path| path[/.+\/(.+).rb/,1] }
ar_models = all_models.select{|m|
m.classify.constantize < ActiveRecord::Base}
ar_models.each do |model|
model_class = model.classify.constantize
if model_class.send("attr_accessible").empty? &&
model_class.send("attr_protected").empty?
puts model_class.class_name +
" allows unprotected mass assignment"
end
end
end
end
[/sourcecode]
(Hat tip Matt for the snippet to find all models).
[sourcecode language='ruby']
namespace :utility do
desc 'Find models that are not using attr_accessible'
task :audit_attr_accessible => :environment do
all_models = Dir.glob(
File.join(Rails.root, 'app', 'models', '*.rb')
).map{|path| path[/.+\/(.+).rb/,1] }
ar_models = all_models.select{|m|
m.classify.constantize < ActiveRecord::Base}
ar_models.each do |model|
model_class = model.classify.constantize
if model_class.send("attr_accessible").empty? &&
model_class.send("attr_protected").empty?
puts model_class.class_name +
" allows unprotected mass assignment"
end
end
end
end
[/sourcecode]
(Hat tip Matt for the snippet to find all models).
Double Shot #350
Round numbers of these things always make me happy.
Introducing Cache Money - Gem from the Twitter folks to implement write-through caching with Active Record and Memcached.
Fun with Threads - Further discussion of how Rails is tackling threading, from Koz.
Future proofing your Ruby code. Ruby 1.9.1 is coming. - Advice from Dr. Nic.
A case against Mocking and Stubbing and A case against a case against mocking and stubbing - Back-and-forth with Brian Cardarella and David Chelimsky.
Double Shot #349
I've gone back to big pieces of paper (actually giant Post-It Notes) for ERDs. Feels very satisfying in the absence of acres of whiteboards.
Why Ruby is Not My Favorite Language - An objection to promiscuous reopening of classes, though I think the counterarguments in the comments are reasonable.
FriendDA - An alternative to a serious NDA. I wouldn't dream of using this in business, but it's amusing.
Rails Worst Practices: 13 Coding Nightmares You Should Avoid - A reasonable list to think about, but I'm wary of "all" or "never" pronouncements.
Double Shot #348
Does anyone actually like end of the year bookkeeping?
Rails, Ajax and jQuery - I'm not all that fond of AJAX, but if you are, this is worth a look - it avoids all the Rails helper methods in favor of just writing the JavaScript.
Capistrano 2.5.3 - Jamis is no longer going to knock himself out to support Windows. I think that's just dandy.
HTTP Client - Little HTTP debugging tool for OS X. Nothing you couldn't do with the right Firefox extensions, but it's purty.
Firefox 3.1 Beta 2 - Time to upgrade again if you're on the cutting edge.
Double Shot #347
It's another new week, full of hope.
simplepay - Rails interface to Amazon Simple Pay payment service.
Using Google App Engine as Your Own Content Delivery Networkm - A useful idea if your traffic isn't too huge.
TortoiseGit Challenge - The GitHub folks want to see better Windows client software, and are offering a bounty for it.
CSV Mapper - Library to simplify importing CSV to Ruby apps. I may have a use for this soon.
Ruby on Rails Hosting Round-up - Always a popular (and mildly controversial) subject.
RPX in Action - If I ever have to implement OpenID, this looks like a good way to go about it. I'm hoping I never have to, though.
KnockKnock - Google authentication API for Ruby. As far as I'm concerned a better bet than OpenID.
Compass - A Sass-Based CSS Meta-Framework. Looks interesting, but I think that might be just a bit too much abstraction layer over something I barely understand anyhow.
Bug Trackers I Have Known
Or at least, bug trackers I have known lately, because I've used too darned many over the years. Someone recently asked me to summarize my experiences, and who can resist that kind of request?
If I were running a team of 10+ developers and choosing the tools, I'd start with FogBugz, which to my mind still does the best job I've seen of tying everything together and giving good predictive information. But I may be prejudiced, since they paid me to write a book
. I've used FogBugz on real-world projects and been quite happy with it, and for a medium-sized dev team I recommend it.
But these days, that's not the sort of development team I'm usually a part of. Typically, I'm coming into a situation where a smaller team - 2 or 3 developers, 1 or 2 business folks - have already picked their tools, and I need to adapt. The collaboration software ranges from simple lists to full-blown project management tools. Here are some of the ones I've had to deal with in the past 2 years.
It may be heresy for me to say this, but I've never had an especially good experience with Basecamp. It tends to be too much overhead for a small team and to be too opinionated (in my never-humble opinion). Unless you're making a commitment to it for multiple projects, it's just too much bother to use, and too hard to customize.
Redmine is also not one of my favorites. Yes, it's written in Rails, but other than that, I think it's just behind the times. Entering a lot of data fields on a pure text interface doesn't mesh well with the way I do business. If they add a really slick git integration I might take another look, but my overall feeling is that there are just better tools out there.
The venerable Trac is another one that I can find my way around when I need to, but can't especially recommend. The integrated wiki is on the clunky side, and the whole system feels slow (that might be a consequence of the installations I've had access to, of course). I don't like Trac's reporting or workflow either.
No Kahuna has been excellent for small projects with clients who are less technically savvy. It offers an extremely simple interface, closer to a task manager than a bug tracker, but that's what some people need. It supports multiple projects and tasks, and ranking things into buckets, and tracking who's working on them. There are things I don't like - such as multiple clicks to get back to the full task list after finishing a tasb - but this is one of the tools I end up recommending to people who just want collaborative tracking without a lot of fuss.
Hiveminder is another collaborative todo list that I've used on multiple projects. It's got more bells and whistles than No Kahuna (and sometimes all the AJAXy stuff seems to slow it down), which makes it harder to learn to use effectively. I also find that its notion that you have a big bucket of "up for grabs" tasks doesn't always play well with knowing who is responsible for what.
Lighthouse is another darling of the Rails world that I can take or leave. I like that it is low-ceremony, focusing on what needs to be done rather than on entering a bunch of excess data. I don't so much like the navigation or searching, which seem confusing at times.
Pivotal Tracker I've just started using on one project, and I like it so far. The drag-and-drop UI makes the client happy because they can prioritize the work, and the simple tracking makes me happy because I can get it done. I don't like the 0,1,2,3 scale for story points, and so far I don't know how well its velocity tracking/prediction will work, but my initial impression is that this is one I'm going to hang on to.
If I were running a team of 10+ developers and choosing the tools, I'd start with FogBugz, which to my mind still does the best job I've seen of tying everything together and giving good predictive information. But I may be prejudiced, since they paid me to write a book
. I've used FogBugz on real-world projects and been quite happy with it, and for a medium-sized dev team I recommend it.
But these days, that's not the sort of development team I'm usually a part of. Typically, I'm coming into a situation where a smaller team - 2 or 3 developers, 1 or 2 business folks - have already picked their tools, and I need to adapt. The collaboration software ranges from simple lists to full-blown project management tools. Here are some of the ones I've had to deal with in the past 2 years.
It may be heresy for me to say this, but I've never had an especially good experience with Basecamp. It tends to be too much overhead for a small team and to be too opinionated (in my never-humble opinion). Unless you're making a commitment to it for multiple projects, it's just too much bother to use, and too hard to customize.
Redmine is also not one of my favorites. Yes, it's written in Rails, but other than that, I think it's just behind the times. Entering a lot of data fields on a pure text interface doesn't mesh well with the way I do business. If they add a really slick git integration I might take another look, but my overall feeling is that there are just better tools out there.
The venerable Trac is another one that I can find my way around when I need to, but can't especially recommend. The integrated wiki is on the clunky side, and the whole system feels slow (that might be a consequence of the installations I've had access to, of course). I don't like Trac's reporting or workflow either.
No Kahuna has been excellent for small projects with clients who are less technically savvy. It offers an extremely simple interface, closer to a task manager than a bug tracker, but that's what some people need. It supports multiple projects and tasks, and ranking things into buckets, and tracking who's working on them. There are things I don't like - such as multiple clicks to get back to the full task list after finishing a tasb - but this is one of the tools I end up recommending to people who just want collaborative tracking without a lot of fuss.
Hiveminder is another collaborative todo list that I've used on multiple projects. It's got more bells and whistles than No Kahuna (and sometimes all the AJAXy stuff seems to slow it down), which makes it harder to learn to use effectively. I also find that its notion that you have a big bucket of "up for grabs" tasks doesn't always play well with knowing who is responsible for what.
Lighthouse is another darling of the Rails world that I can take or leave. I like that it is low-ceremony, focusing on what needs to be done rather than on entering a bunch of excess data. I don't so much like the navigation or searching, which seem confusing at times.
Pivotal Tracker I've just started using on one project, and I like it so far. The drag-and-drop UI makes the client happy because they can prioritize the work, and the simple tracking makes me happy because I can get it done. I don't like the 0,1,2,3 scale for story points, and so far I don't know how well its velocity tracking/prediction will work, but my initial impression is that this is one I'm going to hang on to.
Double Shot #346
Has anyone seen my missing productivity?
Ruby-Locale - Localization library that works with the Rails 2.2 i18n bits.
Ruby on Rails Online Class - For real college credit, even. Starting in February, cheap if you're a California resident.
RubyGem is from Mars, AptGet is from Venus - One of the more sensible pieces I've seen on gems vs. Debian.
PoolParty - Software for configuring and managing computing clouds with a feel similar to Capistrano.
jCquard - JavaScript library to manage 80-column punch cards.
A Little RAILS_ROOT Tidiness
Ever write code like this in Rails?
[sourcecode language='ruby']
if File.exists?(File.join(RAILS_ROOT, 'config', 's3.yml'))
has_attached_file :s3_image,
:storage => :s3,
:s3_credentials => File.join(RAILS_ROOT, 'config', 's3.yml')
end
[/sourcecode]
That particular snippet is from an application that optionally uses Amazon S3 to store images, if there is a configuration file for S3 supplied in the deployment. Well, you can clean that up a bit. First, although the
[sourcecode language='ruby']
if File.exists?(Rails.root.join('config', 's3.yml'))
has_attached_file :s3_image,
:storage => :s3,
:s3_credentials => Rails.root.join('config', 's3.yml')
end
[/sourcecode]
A tiny improvement, but of such tiny improvements are a pleasant framework made.
[sourcecode language='ruby']
if File.exists?(File.join(RAILS_ROOT, 'config', 's3.yml'))
has_attached_file :s3_image,
:storage => :s3,
:s3_credentials => File.join(RAILS_ROOT, 'config', 's3.yml')
end
[/sourcecode]
That particular snippet is from an application that optionally uses Amazon S3 to store images, if there is a configuration file for S3 supplied in the deployment. Well, you can clean that up a bit. First, although the
RAILS_ROOT
constant is still supported, we've had the prettier-looking Rails.root
for months. Second, as of a recent commit to edge rails, Rails.root
returns a Pathname
object, so it directly supports the join
method. Hence, the code snippet above can now be:[sourcecode language='ruby']
if File.exists?(Rails.root.join('config', 's3.yml'))
has_attached_file :s3_image,
:storage => :s3,
:s3_credentials => Rails.root.join('config', 's3.yml')
end
[/sourcecode]
A tiny improvement, but of such tiny improvements are a pleasant framework made.
Double Shot #345
Doesn't feel like I have enough projects to justify the amount of busy I am. Not sure what that's about.
jquery_grid_for_rails - Rails wrapper for a fancypants UI grid. I'm not a huge fan of grid UIs in general, but sometimes they're useful.
authlogic-activation-tutorial - A tutorial as a git project. Perhaps not the most effective presentation but easy to edit.
db_branch - Rails plugin to manage databases across git branching. I've been on projects where this would have been very useful.
How I use TextMate - A few tips from Alex Payne.
Rails Templates - The first must-have feature of the 2.3 branch. Notes from Pratik Naik.
Double Shot #344
Win some, lose some: good new client onboard yesterday, several older clients delinquent in their payments. The joy of freelancing.
simplelog - A new alternative on the Rails blogging engine front.
Spree 0.5.1 - This open source commerce platform is now designed to work with any Rails 2.1 version.
Zero-Downtime Restarts with HAProxy - In my ideal world, other people take care of this level of server fu for me.
Hot in Edge Rails: Generate Rails Apps from Templates - This is indeed hot, and will largely replace the need to keep static template applications hanging around.
Ruby Advent 2008 - An article a day for the holiday season.
Double Shot #343
Sometimes distributed team project management is very trying.
See Rails request paths in 'top' - A nice idea from Dave Thomas. I wonder if this should make its way into core.
TextMate Productivity Tips - From 456 Berea St. Tips are always fun.
cuc-demo - A demonstration of BDD with cucumber in the form of a tagged git repository.
Ruby 1.9.1 Preview 2 - It's getting closer.
Why Git is Better than X - Just in case you want reasons to switch.
subscribe via RSS