布局中的模态div:
main
= render 'layouts/desktop_sidebar'
#modal-window.modal aria-labelledby="myModalLabel" role="dialog" tabindex="-1"
.main-content
= render 'flash'
= yield
模态内容:
.modal-dialog role="document"
.modal-content
.modal-header
button.close aria-label="Close" data-dismiss="modal" type="button"
span aria-hidden="true" ×
h4#myModalLabel.modal-title Modal title
.modal-body
| Test body content
.modal-footer
button.btn.btn-default data-dismiss="modal" type="button" Close
button.btn.btn-primary type="button" Save changes`
链接到切换模式:
= link_to 'Quick Add', companies_quick_add_path, remote: true, data: { toggle: "modal", target: '#modal-window' }
quick_add.js.erb
$("#modal-window").html("<%= escape_javascript(render 'quick_add') %>");
客户端控制器操作:
def quick_add
@client = Client.new
initialize_client_children
respond_to do |format|
format.html
format.js
end
end
在点击链接之前DOM: Image
单击链接后DOM: Image
单击链接以渲染模态时,它会点击控制器操作并成功到达视图部分。屏幕变暗,但模态根本不显示。
当将模态移出partial并将模态内容放在div和id声明的正下方时,模型将呈现,但我显然无法访问控制器变量。
答案 0 :(得分:0)
"#modal-window"
元素在哪里?您应该选择.modal-body
。如:
$(".modal-dialog .modal-body").html("<%= escape_javascript(render 'quick_add') %>");