我正在尝试在 Bootstrap 弹出窗口中渲染 form_for 部分,由于某种原因,表单似乎没有正确关闭,从而破坏了弹出窗口。
_post_form.html.erb
test_text_1
<%= form_for(@reblog) do |f| %>
<%= f.text_field :content %>
<%= f.submit %>
<% end %>
test_text_2
调用弹出框和表单的 View 助手:
def reblog_post(reblog)
button_tag(class: "btn btn-xs", data: { toggle: "popover", placement: "bottom", html: true, content: (render partial: "shared/post_form") }) do
'<a><span class="glyphicon glyphicon-retweet"></span></a>'.html_safe
end
end
当只有纯文本或 html 时,弹出窗口工作得很好,但是一旦我将 form_for 放入其中,form_for 之后的所有内容(即 test_text_2 以及表单元素)都会呈现在弹出窗口之外,带有尾随 ">
,这使得表单字段看起来没有正确关闭。表单之前的任何纯文本(例如 test_text_1)仍然可以在表单内正确呈现。我是否缺少拼写错误,或者是否有特定的方法在 Bootstrap 弹出窗口中呈现表单?
最佳答案
而不是
内容:(渲染部分:“shared/post_form”)
尝试:
内容:“#{渲染部分:'shared/post_form'}”
您还想确保 popover
初始化接受 html 内容(默认仅为文本),即 $("#id").popover({html: 'true'})
http://getbootstrap.com/javascript/#popovers-options
干杯
关于javascript - Rails 形成部分中断 Bootstrap 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38710663/