This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
Original Post: What's New in Edge Rails: An Explicit Locals Hash
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.
With Rails components being shunned throughout the Rails world we are often left to use a set of view partials to abstract out commonly used display functionality. Sometimes this necessitates the use of variables (called ‘locals’) that may or may not be relevant in all view scenarios. For instance, if I have a partial that I use to display form text fields there may be a size parameter I want to pass in to limit the field’s size:
However, this fails if no size parameter is passed to the partial as size hasn’t been defined yet. With this update, however, you can query an explicit locals hash to determine the existance of a local variable: