Rails 4,让所有本地人都处于局部

Max*_*vak 9 partial-views ruby-on-rails-4.1

如何在局部视图中将所有本地作为哈希.

# mainview.html.haml:
= render 'v1', p1: 100, p2: 'some_value', _other_values_
Run Code Online (Sandbox Code Playgroud)

在局部视图中:

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

# render another partial view

= render 'another_view', locals: locals # what to write here???
Run Code Online (Sandbox Code Playgroud)

如何访问本地中的所有变量作为哈希.我不想在本地列出所有变量.

Max*_*vak 10

使用local_assigns.

local_assigns #=> { p1: 100, p2: 'some_value', _other_values_ }
Run Code Online (Sandbox Code Playgroud)

_v1.html.haml

= render 'another_view', local_assigns
Run Code Online (Sandbox Code Playgroud)