我剛剛從敏捷Web開發的Rails中學習Ruby on Rails。即使我在控制器中完成了redirect_to,模板仍然缺少錯誤
做一個購物車應用程序,並在實施「空購物車」功能的過程中。
<%= button_to 'Empty cart', @cart, method: :delete,
data: { confirm: 'Are you sure?' } %>
點擊「清空購物車」按鈕調用在車控制器
# DELETE /carts/1
# DELETE /carts/1.json
def destroy
@cart = current_cart
@cart.destroy
@session[:cart_id] = nil
respond_to do |format|
format.html { redirect_to store_url, notice: 'Your cart is currently empty' }
format.json { head :no_content }
end
end
在這裏,我重定向到store_url而是它給了我一個錯誤的破壞行動。
模板丟失 缺少模板推車/破壞,應用/使用{破壞:區域設置=> [:EN]:格式=> [:HTML]:處理程序=> [:ERB,:助洗劑, :raw,:ruby,:jbuilder,:coffee]}。搜查:* 「/用戶/ anil20787 /工作區/ railsdir /庫/應用/視圖」
這裏是輸出耙路線
Prefix Verb URI Pattern Controller#Action
line_items GET /line_items(.:format) line_items#index
POST /line_items(.:format) line_items#create
new_line_item GET /line_items/new(.:format) line_items#new
edit_line_item GET /line_items/:id/edit(.:format) line_items#edit
line_item GET /line_items/:id(.:format) line_items#show
PATCH /line_items/:id(.:format) line_items#update
PUT /line_items/:id(.:format) line_items#update
DELETE /line_items/:id(.:format) line_items#destroy
carts GET /carts(.:format) carts#index
POST /carts(.:format) carts#create
new_cart GET /carts/new(.:format) carts#new
edit_cart GET /carts/:id/edit(.:format) carts#edit
cart GET /carts/:id(.:format) carts#show
PATCH /carts/:id(.:format) carts#update
PUT /carts/:id(.:format) carts#update
DELETE /carts/:id(.:format) carts#destroy
store_index GET /store/index(.:format) store#index
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PATCH /products/:id(.:format) products#update
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
store GET / store#index
我沒看this和this職位這與我的問題類似。但我無法弄清楚需要做什麼。
任何幫助解決這個問題表示讚賞。
編輯: - 增加{}周圍redirect_to的 - 增加了 '耙路線' 輸出
是否缺少了{}重定向身邊? – sevenseacat
使用{}周圍重定向。於事無補。錯誤仍然存在。 – bobdiya
u能表明耙路後輸出? – AnkitG