Reputation: 3992
In my rails app, I want to use modal to open a new page.
For example, in the index.html.erb
, I have a button "New". When I click "New", a dialog would display the content in new.html.erb
. I tried to use:
<a data-toggle="modal" class="btn btn-info" href="#{new_site_path}" data-target="#myModal">New</a>
But it's not working, what is the best rails way to do that? Thanks.
Updated:
I found a way that is:
<%= link_to "Open modal", new_site_path, :class => "btn", "data-toggle" => "modal", "data-target" => ".bs-example-modal-lg" %>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
</div>
</div>
</div>
However, the open dialog is include the html code in application.html.erb
which include the navigation bar and side bar, but I don't want it, how can I do that?
Thanks.
Upvotes: 0
Views: 667
Reputation: 5905
The link should be:
<a data-toggle="modal" class="btn btn-info" data-target="#myModal">New</a>
Now create a partial
in the page where that upper a
tag contains. Suppose, you have created _modal_patrial.html.erb
. then render
the partial in the current page.
on _modal_patrial.html.erb
:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
// new.html.erb contents will go here.
</div>
You can see this link for details. Hope it helps!
Upvotes: 1