A Fresh Cup is Mike Gunderloy's software development weblog, covering Ruby on Rails and whatever else I find interesting in the universe of software. I'm a full-time Rails developer and contributor, available for long- or short-term consulting, with solid experience in working as part of a distributed team. If you'd like to hire me, drop me a line. I'm also the author of Rails Rescue Handbook and Rails Freelancing Handbook.

Navigation
« Double Shot #358 | Main | Double Shot #357 »
Friday
26Dec2008

Coming in Rails 2.3: Simpler Rendering

Over the years, 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 => "<% @product.name %>"
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]

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>