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?
2 Answers
You can do :locals => { :rawr => @rawr, :hello => @hello } and then the variables will be available within the partial as rawr and hello.
2 Comments
NullVoxPopuli
but what if a want @rawr and @hello?
John Topley
You can't have them. What's the problem with referring to
rawr and hello in your partial?You know, you could just use @rawr and @hello ... and NOT pass any variables.
2 Comments
sscirrus
In that case, is there ever a reason to pass locals instead of just using the existing variables?
Omar Qureshi
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.