简体   繁体   中英

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 "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

<div class="modal" id="loginModal">
    Test Content
</div>

in 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. You can do something like this to get the same results.

<%= link_to 'Click Here', "#", data: {toggle: "modal", target: "#modal"} %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM