I am working on a rails application.in a use case where I have to pop up a modal.problem is that modal is not popping up. if I make the partial file as normal then modal appears as a normal page which I don't want. since a week I am trying this little good news is at least it is showing the modal if I do _load_users.html.erb as load_users.html.erb but I want the partial file to be popped up as the modal.
I have used a link which triggers Ajax
// teams_controller
def load_users
@user = User.all
respond_to do |format|
format.html
format.js
end
end
//index.html.erb
<%= link_to 'link', load_users_teams_path, remote: true %>
<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content"></div>
</div>
</div>
//_load_users.html.erb
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
**here comes whatever you want to show!**
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
//load_users.js.erb
$("#modal-window").html("<%= escape_javascript( render 'load_users' ) %>");
$("#modal-window").modal()
It should show a pop-up modal on click of the link.
With your original setup was there nothing happening in the DOM or errors in browser console?
<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content"></div>
</div>
</div>
Any change to this as viewed in developer tools inspector when you click your remote link?
Might just be that when you replace the content of the #model-window that it still has the .hide class (I'm guessing this is display: none; or similar).
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.