使用jQuery酥料餅的CRUD我嘗試添加的jQuery酥料餅到軌默認cruds而不是redireting到的意見和什麼我做的是呈現形式,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。現在我們必須在popover函數中獲取錨點ID,但$(this).id不起作用。任何建議?
是的,但仍有問題。我們不能在erb標籤中使用這樣的行:「<%=」+「escape_javascript ....(您的代碼)」+「%>」。這是行不通的。我們在erb文件中。每個<%=翻譯成ruby代碼,如果我們使用「\ <\%\ =」,那麼它不會作爲ruby代碼執行。 – Pooya
哪部分不起作用?你能否更新你的問題以包含來自erb的代碼? – jibai31
整個提到的代碼是在erb中。 – Pooya