Ich habe eine Liste von Elementen, die gelöscht oder bearbeitet werden können. Ich möchte es so implementieren, dass, wenn ein Benutzer auf Bearbeiten klickt, ein Modal mit den bereits vorab gefüllten Informationen angezeigt wird. Ich kann es nicht zur Arbeit bringen.Wie man ein modales partielles rendert?
_items.haml
- @items.each do |item|
.col-lg-2.col-md-3.col-sm-3.col-xs-12
.partial.item
.pad10
%label #{item.title}
= link_to item_path(item), :class => "btn-xs", :method => "put", remote: true do
edit
= link_to "x", item_path(item), :method => :delete, :data => {:confirm => "Are you sure?"}, :class => "btn-xs"
%h2.item-num
= "#{item.result}"
items_controller.rb
def update
@item = Item.find(params[:id])
@feature = @item.feature
respond_to do |f|
f.js { render layout: false }
f.html
end
end
update.js.erb
<%= j render(:partial => 'edit_item', locals: { item: @item, feature: @feature }) %>
$('#editItem').modal('show');
_edit_item.haml
#editItem.modal.fade
.modal-dialog
.modal-content
.modal-header
%button.close
x
.modal-body
= form_for @item do |f|
.dev
.col-lg-7.col-xs-12
.well
.row
.col-md-9.col-xs-9
%h4 Edit Item
.col-md-3.col-xs-3
.btn.form-control Cancel
.row
= f.hidden_field :feature_id, :value => @feature.id
.col-md-6.col-xs-12
= f.label :count
= f.select(:count, ["Select"] + Item.counts(@feature), {}, { :class => "form-control input", :id => "column" })
.col-md-3.col-xs-12
= f.label :calculation
= f.select(:calculation, ["Select"] + Item.calculations, {}, { :class => "form-control input", :id => "column" })
.col-md-3.col-xs-12
= f.label :format
= f.select(:format, Item.formats, {}, { :class => "form-control input", :id => "column" })
.col-md-12.col-xs-12
= f.label :title
= f.text_field :title, :class => "form-control input-sm", :value => "i.e. Total Billing"
%br
.row
.col-md-12.col-xs-12
= f.submit "Save", :class => "btn form-control btn-primary"