ビューにリダイレクトする代わりに、jquery ポップオーバーを Rails のデフォルト cruds に追加しようとしましたが、jquery ポップオーバーでフォームをレンダリングしています。
<%= content_tag_for :tr, @order.order_items do |i| %>
<a class='btn btn-mini label-with-popover' id=<%=i.id%>><%= t('helpers.links.edit_html') %> </a>
<% end %>
<script type="text/javascript">
$(function () {
$('.label-with-popover').popover({
html : true,
content: "<%= escape_javascript(render :partial => 'form_item') %>" ,
placement: 'top'
} );
});
</script>
ここに私のform_itemがあります:
<%= simple_form_for :order_item, url: admin_shop_order_path, :html => { :class => 'form-horizontal' } do |f| %>
<div class='form-inputs'>
<%= f.input :item_id , :collection => @shop.products.collect{|b| b.variants}.flatten.map{|variant| ["#{variant_full_title(variant)}", variant.id]}%>
<%= f.input :quantity %>
</div>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t("helpers.links.cancel"), admin_shop_orders_path, :class => 'btn' %>
</div>
<% end %>
しかし、問題は編集ボタンに表示されます。編集フォームをレンダリングするには、編集するオブジェクト(:order_item) が必要です。これを取得するには、id を使用します。これが、アンカー タグ id を設定した理由です。ポップオーバー関数内でそのアンカー ID を取得する必要がありますが、$(this).id は機能しません。なにか提案を?