Saturday, 14 May 2011

Rails 3 partial views

I got caught out today trying to use a Rails 3 partial view.. I was passing a local in to it but it just wasn't getting picked up.

=render "shared/cat_box", :locals => {:cat => @cat}

ActionView::Template::Error (undefined local variable or method `cat' for #<#<Class:0x1062afad8>:0x1062aa240>)

Scratching my beard for a while until I realised that maybe render only looks for locals in the first parameter hash.. e.g. using the full way of rendering a partial:

=render :partial => "shared/cat_box", :locals => {:cat => @cat}

All working fine now!

No comments:

Post a Comment