0

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 2

2

You can do :locals => { :rawr => @rawr, :hello => @hello } and then the variables will be available within the partial as rawr and hello.

Sign up to request clarification or add additional context in comments.

2 Comments

but what if a want @rawr and @hello?
You can't have them. What's the problem with referring to rawr and hello in your partial?
1

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

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.