Michael Bensoussan home

Optional local in partial that doesn’t break

22 May 2010

If you have a partial called with or without local parameters, example :

= render :partial => 'user/new'
= render :partial => 'user/new', :locals => { :show_ad => true }

And you don’t want the partial to break when the local isn’t assigned, you can access it through the local_assigns variable :

- if local_assigns[:show_ad]
  = render :partial => "ad"


blog comments powered by Disqus