So... I know about the :locals => { :var1 => @rawr, :var2 => @hello }
syntax for partials
but is there a way for me to pass both @rawr
and @hello
to the partial, so that i don't need to use var1
and var2
?
views:
33answers:
2
+1
A:
You can do :locals => { :rawr => @rawr, :hello => @hello }
and then the variables will be available within the partial as rawr
and hello
.
John Topley
2010-07-02 14:26:44
but what if a want @rawr and @hello?
DerNalia
2010-07-02 14:45:13
You can't have them. What's the problem with referring to `rawr` and `hello` in your partial?
John Topley
2010-07-02 16:05:35
+1
A:
You know, you could just use @rawr and @hello ... and NOT pass any variables.
Omar Qureshi
2010-07-02 16:32:50
In that case, is there ever a reason to pass locals instead of just using the existing variables?
sscirrus
2010-07-02 21:01:44
Yeah, if you dont have an instance variable already, or you might want to pass a variation on that instance variable, or loads of other reasons.The key is to not set instance variables unnecessarily and use local variables wherever possible to avoid trampling of variable names.
Omar Qureshi
2010-07-02 22:37:50