calling partials from a layout - once nil, once not nil

Michal Burak wrote:

-------- home/_current_user.pl.html.erb : --------
<% if current_user %>
  NOT NIL
<% else %>
  NIL
<% end %>

-------- home/_user_box.pl.html.erb : --------
<% if current_user %>
  NOT NIL
<% else %>
  NIL
<% end %>

-------- layouts/layout.html.erb : --------
<%= render :partial => '/home/current_user' -%>
<%= render :partial => '/home/user_box' %>

Why is that so? Why one time it is nil and the other time it is not nil?

Any help appreciated.

Regards.

It has to do with the name of the partial, Rails does some magic by
looking at the name of the partial and then making a local variable
(with the same name as the partial) accessible to that partial.

i.e. a partial entitled "_current_user" will have current_user as a
local whereas a partial entitled "_user_box" will have user_box as a
local.

This was new functionality introduced with rails 2 I believe..

Don't forget that the render() can have :object and :locals passed into
it..

hth

ilan