我正在尝试为我的物品添加“添加到购物车”方法。没有路线匹配[GET]
items_controller:
def to_cart
@item = Item.friendly.find(params[:id])
@item.add_to_cart
redirect_to root_path
end
路线:
resources :items do
put :to_cart, on: :member
end
型号:
def add_to_cart
current_user.cart.items << self
current_user.cart.save
end
显示:
<%= @item.name %>
<%= link_to 'add to cart', to_cart_item_path(@item) %>
我得到了RoutingError:No route matches [GET] "/items/first/to_cart"
'第一'因为友好的id。 我做错了什么?
您可以将您的routes.rb?您需要在resources:items行添加'member::to_cart'。 –