Rails: get arguments passed to partial

412 Views Asked by At

Is it possible to get the arguments passed to a partial from within the that partial?

# in some_view.html.haml
= render 'foo_partial', some: "stuff", goes: "here"

# in foo_partial.html.haml
= arguments = ??? # im trying to get this to contain {some: "stuff", goes: "here"}

NOTE To clarify, I wanted to view all the arguments that were passed to the partial.

EDIT 2 I'm not asking how to access the variables, but to get a list of everything that was passed in. Mods, please do not change the code provided as it is an example of my situation. Changing code has implications on the question itself.

Thanks

3

There are 3 best solutions below

0
On BEST ANSWER

What I was looking for was local_assigns

# in some_view.html.haml
render 'foo_partial', some: "stuff", goes: "here"

# in foo_partial.html.haml
= local_assigns # outputs {some: "stuff", goes: "here"}
0
On

You want to pass them as locals

render 'foo_partial', locals: {some: "stuff", goes: "here"}

You can call them in your view by their key

some will return "stuff"

0
On

You can pass local variables into partials like this :

= render partial: 'foo_partial', locals: {some: "stuff", goes: "here"}