[英]How to use bootstrap Modal with link_to in rails?
I had asked this earlier but unfortunately I am still stuck. 我之前曾问过这个,但不幸的是我仍然被卡住了。 I have a link_to like this 我有一个像这样的link_to
<%= link_to "Click Here", page_path,, :id => 'login', "data-toggle" => "modal" %>
in page.html.erb (the page which I want to load in modal when the link gets clicked),I have 在page.html.erb(我想在点击链接时以模态加载的页面),我有
<div class="modal" id="loginModal">
Test Content
</div>
in assets/page.js.coffee 在assets / page.js.coffee中
$('#loginModal').modal(options)
but still, the link is not opening in a modal Any help ? 但仍然,链接不是以模态打开任何帮助?
添加data-target
<%= link_to "Click Here", page_path, :id => 'login', "data-toggle" => "modal", 'data-target' => '#loginModal' %>
There is a prettier way to add data
attributes in Rails. 在Rails中添加data
属性有一种更漂亮的方法。 You can do something like this to get the same results. 您可以执行类似的操作以获得相同的结果。
<%= link_to 'Click Here', "#", data: {toggle: "modal", target: "#modal"} %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.