【问题标题】:Rails + Bootstrap: Render partial with locals in Bootstrap popoverRails + Bootstrap:在 Bootstrap 弹出窗口中使用本地人渲染部分内容
【发布时间】:2014-05-28 22:27:48
【问题描述】:

当我在 Bootstrap 弹出窗口中渲染它时,我想将一个局部变量传递给我的局部变量。这就是我所拥有的,尽管我很确定我没有在 content_tag 中正确渲染部分内容。

 <%= content_tag :button, type: "button", class: "btn btn-default",
 :data => { container: "body", toggle: "popover", placement: "bottom",
 content: "#{render 'layouts/quick_add_form', :locals => {:code => item1.code}}"} do %>

          button

 <% end %>

非常感谢任何帮助!

编辑

当前局部变量没有被传递给局部变量,因此:code 属性没有保存在表单提交中。

【问题讨论】:

  • 请编辑您的问题 - 使用 } 关闭 :data 键的值。

标签: ruby-on-rails twitter-bootstrap


【解决方案1】:

我不相信你可以在 HAML 中使用 #{}(哦等等,我看到 #{} 被用作常规的 Ruby 字符串插值 - 我认为它会起作用)。不仅如此,当你在一个partial 上调用render 并且你想传递额外的值时,出于某种原因(对于某些Rails 版本),你必须明确地将它声明为partial:

render partial: 'layouts/quick_add_form', :locals => {:code => item1.code}

至少可以在 ERB 或 HAML 中使用。

您还应该通过在浏览器中查看 CTRL-U 源代码来验证生成的 HTML 在 data 属性中是否正确转义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多