<%=
button_tag class: "btn btn-primary",
data: { toggle: "modal", target: "#exampleModal", name: member.name } do
modal_member = Member.find(member.id)
content_tag(:b, 'Open Modal')
end
%>
我要创建变量名'modal_member' 使用button_tag
因为bootstrap模态但它不起作用
我认为定义代码效果不佳
我的目标是将变量定义或传递给按钮或链接标记
答案 0 :(得分:0)
我建议将模态结构插入到erb文件中,然后用你想要的数据填充它。除非你通过js触发它,否则这将是一个不同的故事。
<%=
button_tag class: "btn btn-primary",
data: { toggle: "modal", target: "#exampleModal", name: member.name } do
content_tag(:b, 'Open Modal')
end
%>
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p> <%= member.name %> or whatever data you want</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>