Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4, get all locals in partial

How to get all locals as a hash in a partial view.

# mainview.html.haml:
= render 'v1', p1: 100, p2: 'some_value', _other_values_

in a partial view:

# _v1.html.haml
# do something here...

# render another partial view

= render 'another_view', locals: locals # what to write here???

How to access ALL variables in locals as a hash. I don't want to list all variables in locals.

like image 454
Max Ivak Avatar asked May 09 '15 08:05

Max Ivak


1 Answers

Use local_assigns.

local_assigns #=> { p1: 100, p2: 'some_value', _other_values_ }

_v1.html.haml

= render 'another_view', local_assigns
like image 67
Max Ivak Avatar answered Sep 22 '22 22:09

Max Ivak