check out my new blog at

Thursday, September 27, 2007

rails: optional locals values in partials

As you may know, rails' partial is a proper way for producing reusable view chunks

But sometimes you may need the partial to look different depending on contetext( say partial "_post" is used in "posts_list" and "single_post" templates). No problems - rails gives you :locals option


<%= render :partial => 'post', :locals => {:look_different => true} %>

And then you can do in parial like

<% if look_different %>
<p>look different <p>
<% else %>
<p>look usual <p>
<% end %>

But it gets painful passing all the locals all the time...otherwise you'll get NameError for not passing partial's option

Solution: optional locals values

Core rails team solution

just use local_assigns[:key] to access your local variables :)

<% if local_assigns[:look_different] %>
<p>look different <p>
<% else %>
<p>look usual <p>
<% end %>

from rails 1.2.3 sources
from ActionView::Base docs

Labels: , , , ,

 check out my new blog at

Monday, September 17, 2007

Google code uses jQuery!

Today, surfing around google code i accidentally stoped page loading and found pretty interesting js error:

jQuery("#techtalks .posts").append(f)

Meaning that Google uses jQuery!

jQuery rox! :)

 check out my new blog at

Friday, September 14, 2007

The button element

Here's my fix for a IE button hell(first 2 issues) i've created a while ago actually...

Useful links to read about the Button element:

 check out my new blog at

Sunday, September 02, 2007

Rails: collection index within partial render

Tonight i've found a tiny and nice feature i was missing sometimes...(in order to have it created custom helper)

So when you have:

<%= render :partial => 'games/game', :collection => @games %>

you may sometimes need to access collection index. And you can easily do that by using local variable named by such convention <partial_name>_counter
Like this:


<li> <%= game_counter %> item

PS. and yes you can always use ordered(numbered)lists(ol instead ul)