I am attempting to clean up my code a bit by placing my modal code inside of a partial, however I am encountering problems when trying to call the modal.
I tried the solution provided by How to show twitter bootstrap modal via JS request in rails?, but if I understand correctly I have to add code to a particular controller to display the modal. That would be fine however I would like to display the modal regardless of the controller/view it is in. Is this possible?
What I have (completely from the above question):
current link (views/static_pages)
<%= link_to "ModalTest", 'shared/testmodal', {:remote => true, 'data-toggle' => 'modal', 'data-target' => "testmodal" }%>
show.js.erb
$('.modal-body').html('<%= escape_javascript(render :partial => 'shared/testmodal'%>');
$('.modal-header').remove();
previous attempt:
<%= link_to "ModalTest", render(:partial => 'shared/testmodal') %>
You can include the modal contents you put in the partial, in any view you need or in your application.html
, with:
<%= render "shared/testmodal" %>
And toggle it with:
<%= link_to "ModalTest", "#testModal", "data-toggle" => "modal" %>
Where #testModal
is your modal id
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With