Getting instance variable name

View Rails 2.3 RC1 Release Note I see this:

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

So, somehow the method renderdetects that this object is passed int, it is assigned an instance variable with the name article. How it's done?

+3
source share
2 answers

It actually defines the partial path using the type of the object (model), rather than the name of the instance variable. So, as long as the type is an article, this will work even if the instance variable is @foo.

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

+9
source

Dave Ray - Rails . , , ParseTree, (JRuby, Ruby 1.9 ..).

+1

Source: https://habr.com/ru/post/1703586/


All Articles