Max Ivak
Max Ivak

Reputation: 1549

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.

Upvotes: 10

Views: 3061

Answers (1)

Max Ivak
Max Ivak

Reputation: 1549

Use local_assigns.

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

_v1.html.haml

= render 'another_view', local_assigns

Upvotes: 13

Related Questions