This is an example to illustrate the question:
.post
= render partial: 'avatar', locals: { user: @post.user }
= @post.title
.avatar
= render partial: 'avatar_image', locals: { user: user }
= user.name
= image_tag user.image.url
Passing the locals received by partial _avatar.html.haml
on to partial _avatar_image.html.haml
would eliminate the need to repeat the locals (here: { user: user }
).
I know, I could use instance variables. But I would like to know if there is a way to generically pass all locals received to a underlying partial.
you can use local_assigns
to access the locals hash passed to your partial
.avatar
= render partial: 'avatar_image', locals: local_assigns
= user.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With