我刚刚开始从 Agile Web Development With Rails 学习 Ruby on Rails。
正在做一个购物车应用程序并正在实现“清空购物车”功能。
<%= 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,但它给了我一个错误。
模板缺失
缺少模板 carts/destroy、应用程序/销毁 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索位置:*“/Users/anil20787/workspace/railsdir/depot/app/views”
这是输出耙路线
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 https://stackoverflow.com/questions/7191737/template-is-missing-when-using-redirect-to and this https://stackoverflow.com/questions/5922462/rails-redirect-to-another-controller-method-throwing-template-missing和我的问题类似的帖子。但我不知道需要做什么。
感谢任何解决此问题的帮助。
编辑:
- 在redirect_to周围添加了{}
- 添加了“耙路线”输出