Why can rails not find a route created by a helper? -
i created member route in rails 4:
resources :line_items post 'decrement', on: :member end
and gave matching method in line_items controller:
def decrement @cart = current_cart @line_item = @cart.line_items.find_by_id(params[:id]) @line_item.decrement_quantity respond_to |format| if @line_item.save format.html { redirect_to shop_path, notice: 'line item updated.' } format.js {@current_item = @line_item} format.json { head :ok } else format.html { render action: "edit" } format.js {@current_item = @line_item} format.json { render json: @line_item.errors, status: :unprocessable_entity } end end end
but when try make button:
<%= button_to 'x', decrement_line_item_path(item) %>
i error:
no route matches [post] "/carts/25"
what gives?
your error message is:
no route matches [post] "/carts/25"
but expecting route be: /line_items/25/decrement
, not /carts/25
are line_items
routes nested under carts
? if so, unnest decrement action so:
# in config/routes.rb resources :carts resources :line_items end resources :line_items, only: [] post 'decrement', on: :member end
Comments
Post a Comment