views:

33

answers:

2

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?

+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
but what if a want @rawr and @hello?
DerNalia
You can't have them. What's the problem with referring to `rawr` and `hello` in your partial?
John Topley
+1  A: 

You know, you could just use @rawr and @hello ... and NOT pass any variables.

Omar Qureshi
In that case, is there ever a reason to pass locals instead of just using the existing variables?
sscirrus
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