You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

75 rivejä
1.9 KiB

  1. class LineItemsController < ApplicationController
  2. before_action :set_line_item, only: [:show, :edit, :update, :destroy]
  3. # GET /line_items
  4. # GET /line_items.json
  5. def index
  6. @line_items = LineItem.all
  7. end
  8. # GET /line_items/1
  9. # GET /line_items/1.json
  10. def show
  11. end
  12. # GET /line_items/new
  13. def new
  14. @line_item = LineItem.new
  15. end
  16. # GET /line_items/1/edit
  17. def edit
  18. end
  19. # POST /line_items
  20. # POST /line_items.json
  21. def create
  22. @line_item = LineItem.new(line_item_params)
  23. respond_to do |format|
  24. if @line_item.save
  25. format.html { redirect_to @line_item, notice: 'Line item was successfully created.' }
  26. format.json { render :show, status: :created, location: @line_item }
  27. else
  28. format.html { render :new }
  29. format.json { render json: @line_item.errors, status: :unprocessable_entity }
  30. end
  31. end
  32. end
  33. # PATCH/PUT /line_items/1
  34. # PATCH/PUT /line_items/1.json
  35. def update
  36. respond_to do |format|
  37. if @line_item.update(line_item_params)
  38. format.html { redirect_to @line_item, notice: 'Line item was successfully updated.' }
  39. format.json { render :show, status: :ok, location: @line_item }
  40. else
  41. format.html { render :edit }
  42. format.json { render json: @line_item.errors, status: :unprocessable_entity }
  43. end
  44. end
  45. end
  46. # DELETE /line_items/1
  47. # DELETE /line_items/1.json
  48. def destroy
  49. @line_item.destroy
  50. respond_to do |format|
  51. format.html { redirect_to line_items_url, notice: 'Line item was successfully destroyed.' }
  52. format.json { head :no_content }
  53. end
  54. end
  55. private
  56. # Use callbacks to share common setup or constraints between actions.
  57. def set_line_item
  58. @line_item = LineItem.find(params[:id])
  59. end
  60. # Never trust parameters from the scary internet, only allow the white list through.
  61. def line_item_params
  62. params.require(:line_item).permit(:product_id, :cart_id)
  63. end
  64. end