technicalpickles

Open Source ProjectsCode that Might be Useful to You

Talks I've GivenOn Technologies and Ideas

ThoughtsWhere I Sometimes Write Things

Resume If You Still Believe In Those

Follow Me On

GitHubIf coding is your thing

TwitterIf you tweet

Better partials with better-partials


The other week, Dan Croak pointed out better-partials to me. Hadn’t gotten a chance to play it until now.

The gist of better-partials is that it’s a syntactical sugar for render :partial.

Here’s a typical haml snippet using a partial:

- form_for(@video) do |form|
  = render :partial => '/videos/form', :locals => { :form => form }

With better-partials, we can refactor it to:

- form_for(@video) do |form|
  = partial 'videos/form', :form => form

This saves a little typing, and makes it a bit more clearer:

  • You just say you want a partial, rather than to render a partial
  • Automatically passes in options to :locals (with a few special exceptions)

There are a few other usages of better-partials, but I haven’t gotten to use them yet.

It’s not that big of a deal, but it seems like a nice little improvement to me.

comments powered by Disqus