【问题标题】:Rails 4, get all locals in partialRails 4,部分获取所有本地人
【发布时间】:2015-05-09 08:48:47
【问题描述】:

如何在局部视图中获取所有本地变量作为哈希。

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

局部视图:

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

# render another partial view

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

如何以哈希的形式访问本地变量中的所有变量。 我不想列出本地变量中的所有变量。

【问题讨论】:

    标签: partial-views ruby-on-rails-4.1


    【解决方案1】:

    使用local_assigns

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

    _v1.html.haml

    = render 'another_view', local_assigns
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多