Reputation: 4728
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 ?
Upvotes: 16
Views: 25937
Reputation: 113
Using Rails 7 with Bootstrap 5
<%= link_to 'Add user', '#', {:remote => true, 'data-bs-toggle' => "modal", 'data-bs-target' => '#exampleModal', class: 'nav-link'} %>
Upvotes: 1
Reputation: 7070
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"} %>
Upvotes: 11
Reputation: 20878
Add data-target
<%= link_to "Click Here", page_path, :id => 'login', "data-toggle" => "modal", 'data-target' => '#loginModal' %>
Upvotes: 18