I'm trying to render a HTML with a partial inside of a block but the only thing that renders are the last 4 closing </div>
elements.
Here is my code:
<%= new_item_modal do |i| %>
<div class="modal fade" id="newItemModal" tabindex="-1" role="dialog" aria-labelledby="newItemModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">New Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="new-item" style="overflow:scroll;height:500px;">
<%= render partial: "/items/form", locals: { remote: true, item: @item, categories: @categories }%>
</div>
</div>
</div>
</div>
<% end %>
And my new_item_modal
function:
def new_item_modal(&block)
if current_location.present? && can_access("create", "items")
@item = Item.new
@categories = current_location.categories
block.call
end
end
Your first line should read <%= new_item_modal do |item, categories| %>
<%= new_item_modal do |item, categories| %>
and your new_modal_item
method should have block.call(@item, @categories)
. Make sure you rename the variables passed to the partial (for example, from @item
to item
).
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.