This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
Original Post: What's New in Edge Rails: render Stops Being High-Maintenance
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
render is one of those oft-used view-helper methods that always seems to be a little cumbersome. The most common use is to render a partial within another view:
But this is a lot of work for a simple operation, and now it becomes much simpler. Now the default is to assume that a partial is requested (in the past render a :file was the default) and that the final hash argument is the locals hash. Here is the above functionality using the new syntax:
123456789
# Render the 'article' partial with an article local variablerender 'articles/article', :article => @article# Or even better (same as above)render @article# And for collections, same as:# render :partial => 'articles/article', :collection => @articlesrender @articles
If you’ve got some old render calls hanging around that aren’t using partials you’ll have to specify the :file option now: