views:

136

answers:

2

Looking through the rails 2.3 RC1 release note I see this:

# Equivalent of render :partial => 'articles/_article', :object => @article
render @article

So somehow the render method is finding out the that object passed int it is assigned to an instance variable with the name article. How does it do this?

+9  A: 

It actually determines the partial path using the type of the object (a model), not the name of the instance variable. So, as long as the type is Article, this would work, even if the instance variable is @foo.

See the code for ActionController::RecordIdentifier.partial_path for how the path is calculated from an object.

Dave Ray
+1  A: 

Dave Ray's answer is correct - Rails isn't doing anything with the variable name here. In the general case, the sort of introspection you're asking about is possible with the ParseTree library, but that has portability issues (JRuby, Ruby 1.9, etc.).

Greg Campbell