[英]Rails Prawn UnknownFormat (ActionController::UnknownFormat):
[英]ActionController::UnknownFormat in Rails 5
我有一些產品列表,用戶可以在其中添加/刪除產品列表中的項目。 我希望通過 ajax 使用format.js完成上述迭代
這是我的輸入視圖的一部分,我在哪里可以使用按鈕從產品列表中添加/刪除用戶項目:
.input-number__add
= button_to '', product_add_path(id: product_item), remote: true, class: ''
.input-number__sub
= button_to '', product_reduce_path(id: product_item), remote: true, class: ''
這是我在ProductItemsController 的項目列表中添加數量的方法:
def add_quantity
@product_item.quantity += 1 # increase 1 to the quantity
if @product_item.save
respond_to do |format|
format.js { render partial: 'product_items/add_quantity' }
end
end
end
它所做的是 go 到 'product_items/add_quantity.js.erb' 更新數據並通過 js 響應請求,但是當它讀取 respond_to format.js 時我收到錯誤: ActionController::UnknownFormat ,突出顯示這一行: respond_to做|格式化|
我在之前的問題中看到給出了這個解決方案 respond_to:html, :json 但這對我不起作用。
我該如何解決這個問題?
謝謝你讀我。
您確定路由助手product_add_path
和product_reduce_path
指向add_quantity
端點嗎?
您也可以嘗試強制格式:
product_add_path(id: product_item, format: :js)
注意不要忘記您需要rails/ujs
庫才能使用remote: true
功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.