ruby on rails - No route matches [GET] -
i'm trying add 'add cart' method items.
items_controller:
def to_cart @item = item.friendly.find(params[:id]) @item.add_to_cart redirect_to root_path end routes:
resources :items put :to_cart, on: :member end model:
def add_to_cart current_user.cart.items << self current_user.cart.save end show:
<%= @item.name %> <%= link_to 'add cart', to_cart_item_path(@item) %> i got routingerror: no route matches [get] "/items/first/to_cart" 'first' because of friendly id. did wrong?
add method: :put in link default it's get , rails trying find route get method
<%= link_to 'add cart', to_cart_item_path(@item), method: :put %>
Comments
Post a Comment