Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. resources :line_items do
  2. post 'decrement', on: :member
  3. end
  4.  
  5. def decrement
  6. @cart = current_cart
  7.  
  8. @line_item = @cart.line_items.find_by_id(params[:id])
  9. @line_item.decrement_quantity
  10.  
  11. respond_to do |format|
  12. if @line_item.save
  13. format.html { redirect_to shop_path, notice: 'Line item was successfully updated.' }
  14. format.js {@current_item = @line_item}
  15. format.json { head :ok }
  16. else
  17. format.html { render action: "edit" }
  18. format.js {@current_item = @line_item}
  19. format.json { render json: @line_item.errors, status: :unprocessable_entity }
  20. end
  21. end
  22. end
  23.  
  24. <%= button_to 'X', decrement_line_item_path(item) %>
  25.  
  26. No route matches [POST] "/carts/25"
  27.  
  28. No route matches [POST] "/carts/25"
  29.  
  30. # in config/routes.rb
  31. resources :carts do
  32. resources :line_items
  33. end
  34.  
  35. resources :line_items, only: [] do
  36. post 'decrement', on: :member
  37. end
  38.  
  39. resources :line_items do
  40. post 'decrement', on: :member
  41. end
  42.  
  43. decrement_line_item POST /line_items/:id/decrement(.:format) line_items#decrement
  44. line_items GET /line_items(.:format) line_items#index
  45. POST /line_items(.:format) line_items#create
  46. new_line_item GET /line_items/new(.:format) line_items#new
  47. edit_line_item GET /line_items/:id/edit(.:format) line_items#edit
  48. line_item GET /line_items/:id(.:format) line_items#show
  49. PUT /line_items/:id(.:format) line_items#update
  50. DELETE /line_items/:id(.:format) line_items#destroy
  51.  
  52. <%= button_to 'X', decrement_line_item_path(item), method: :post %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement