【问题标题】:Rails: get arguments passed to partialRails:获取传递给部分的参数
【发布时间】:2015-06-16 15:54:44
【问题描述】:

是否可以从该部分中获取传递给该部分的参数?

# in some_view.html.haml
= render 'foo_partial', some: "stuff", goes: "here"

# in foo_partial.html.haml
= arguments = ??? # im trying to get this to contain {some: "stuff", goes: "here"}

注意为了澄清,我想查看传递给部分的所有参数。

EDIT 2 我不是在问如何访问变量,而是要获取传入的所有内容的列表。Mods,请不要更改提供的代码,因为它是我的情况。更改代码会对问题本身产生影响。

谢谢

【问题讨论】:

标签: ruby-on-rails haml


【解决方案1】:

我要找的是local_assigns

# in some_view.html.haml
render 'foo_partial', some: "stuff", goes: "here"

# in foo_partial.html.haml
= local_assigns # outputs {some: "stuff", goes: "here"}

【讨论】:

    【解决方案2】:

    你可以像这样将局部变量传递给局部变量:

    = render partial: 'foo_partial', locals: {some: "stuff", goes: "here"}
    

    【讨论】:

      【解决方案3】:

      您想将它们作为本地人传递

      render 'foo_partial', locals: {some: "stuff", goes: "here"}
      

      您可以通过他们的键在您的视图中调用他们

      some 将返回 "stuff"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-02
        • 2011-08-10
        • 1970-01-01
        • 2016-04-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多