Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resources :line_items do
- post 'decrement', on: :member
- end
- def decrement
- @cart = current_cart
- @line_item = @cart.line_items.find_by_id(params[:id])
- @line_item.decrement_quantity
- respond_to do |format|
- if @line_item.save
- format.html { redirect_to shop_path, notice: 'Line item was successfully 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
- <%= button_to 'X', decrement_line_item_path(item) %>
- No route matches [POST] "/carts/25"
- No route matches [POST] "/carts/25"
- # in config/routes.rb
- resources :carts do
- resources :line_items
- end
- resources :line_items, only: [] do
- post 'decrement', on: :member
- end
- resources :line_items do
- post 'decrement', on: :member
- end
- decrement_line_item POST /line_items/:id/decrement(.:format) line_items#decrement
- 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
- PUT /line_items/:id(.:format) line_items#update
- DELETE /line_items/:id(.:format) line_items#destroy
- <%= button_to 'X', decrement_line_item_path(item), method: :post %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement