I’m doing some work on partials and am trying to figure out what the
usage of the variables that are currently assigned is.
Consider a case where you have a partial named _user.html.erb. In Rails
2.3, the following variables are assigned:
- options[:as] if options[:as] exists
My question is whether these are all used at the same time. Reducing
the number of variables assigned makes a performance difference that is
particularly noticable in large collections. There are some things that
I’m thinking about, but I want to hear what the normal usage is. Feel
free to tell me this is crazy and people use all three all the time.
- set options[:as] to default to :object. If options[:as] is
objectlocal would not be set.
- set options[:as] to default to the partial name. If options[:as]
is specified, the partial name would not be set. In this case,
would always be set separately.
- a more radical option would be to deprecate the usage of
and default options[:as] to the partial name. This would guarantee that
only a single known name would need to be set each iteration. I am
told, however, that
objectis actually in use.
Are either of these options palatable? Effectively, the question is
object, the name of the partial, and a separate options[:as]
are used all at the same time in the same partial.