Ruby-on-rails 如何在rails中使用带有link_to的bootstrap Modal?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15188850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use bootstrap Modal with link_to in rails?
提问by iCyborg
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 ?
但是,链接没有以模式打开 有什么帮助吗?
采纳答案by Intrepidd
Add data-target
添加 data-target
<%= link_to "Click Here", page_path, :id => 'login', "data-toggle" => "modal", 'data-target' => '#loginModal' %>
回答by kobaltz
There is a prettier way to add dataattributes in Rails. You can do something like this to get the same results.
data在 Rails 中有一种更漂亮的方法来添加属性。你可以做这样的事情来获得相同的结果。
<%= link_to 'Click Here', "#", data: {toggle: "modal", target: "#modal"} %>

