Render Bootstrap modal from partial to rails

I am trying to clear my code a bit by putting my modal code inside partial, however I am having problems trying to call modal.

I tried the solution provided How to show twitter bootstrap modal via JS request in rails? , but if I understand correctly, I need to add code to a specific controller to display the modal. That would be fine, but I would like to display modal, no matter what controller / view it is located. Is it 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') %> 
+4
source share
1 answer

You can include the content of the modality that you place in partial, in any view that you need, or in your application.html , with:

 <%= render "shared/testmodal" %> 

And switch it with:

 <%= link_to "ModalTest", "#testModal", "data-toggle" => "modal" %> 

Where #testModal is your modal id .

+11
source

Source: https://habr.com/ru/post/1432606/


All Articles