I have a modal that I have extracted into a partial in my “shared” folder and will be rendering via a javascript call using a view.js.erb file. I want to render this modal partial, and be able to render another partial block inside of this modal partial, but this needs to be dynamic. I should be able to pass in the partial when I call render on the modal partial. I’ve tried passing in a local with the partial location, and this will work, but it doesn’t really solve cases where I also have locals that I want to pass to the nested partial.
Here’s my code below:
The call from my new.js.erb view file (current w/ a local).
$('body').append('<%= j(render '/shared/modal', :modal_title => "Create a new Question", :partial => "render 'questions/form', :btn_message => 'Create'") %>');
_modal.html.erb
<div class="modal hide" id="modal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3><%= modal_title %></h3>
</div>
<div class="modal-body">
</div>
<%= render partial %>
<!-- <div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div> -->
</div>
This isn’t tested, but let me know if it works for you:
Notice I added the “partial_vars” param and sent it to the partial. Then, in your modal’s shared partial have this: