Guest User

Untitled

a guest
Feb 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. class PaysController < ApplicationController
  2. before_action :set_pay, only: [:create, :show, :edit, :update, :destroy]
  3.  
  4. # GET /pays
  5. # GET /pays.json
  6. def index
  7. @pays = Pay.all
  8. # clear no saved sales:
  9. end
  10.  
  11. # GET /pays/1
  12. # GET /pays/1.json
  13. def show
  14. end
  15.  
  16. # GET /pays/new
  17. def new
  18. @pay = Pay.new
  19. last_pay = Pay.where(estado: "confirmado").maximum('numero')
  20. numero = (last_pay != nil) ? last_pay + 1 : 1
  21. @pay = Pay.create(fecha: Date::current, numero: numero, estado: "draft")
  22. @pay.tickets.build
  23. params[:pay_id] = @pay.id.to_s
  24.  
  25. end
  26.  
  27. # GET /pays/1/edit
  28. def edit
  29. end
  30.  
  31. # POST /pays
  32. # POST /pays.json
  33. def create
  34. @pay = Pay.new(pay_params)
  35.  
  36. respond_to do |format|
  37. if @pay.save
  38. format.html { redirect_to @pay, notice: 'Pay was successfully created.' }
  39. format.json { render :show, status: :created, location: @pay }
  40. else
  41. format.html { render :new }
  42. format.json { render json: @pay.errors, status: :unprocessable_entity }
  43. end
  44. end
  45. end
  46.  
  47. # PATCH/PUT /pays/1
  48. # PATCH/PUT /pays/1.json
  49. def update
  50. respond_to do |format|
  51. if @pay.update(pay_params)
  52. format.html { redirect_to @pay, notice: 'Pay was successfully updated.' }
  53. format.json { render :show, status: :ok, location: @pay }
  54. else
  55. format.html { render :edit }
  56. format.json { render json: @pay.errors, status: :unprocessable_entity }
  57. end
  58. end
  59. end
  60.  
  61. # DELETE /pays/1
  62. # DELETE /pays/1.json
  63. def destroy
  64. @pay.destroy
  65. respond_to do |format|
  66. format.html { redirect_to pays_url, notice: 'Pay was successfully destroyed.' }
  67. format.json { head :no_content }
  68. end
  69. end
  70.  
  71. private
  72. # Use callbacks to share common setup or constraints between actions.
  73. def set_pay
  74. @pay = Pay.find(params[:id])
  75. end
  76.  
  77. # Never trust parameters from the scary internet, only allow the white list through.
  78. def pay_params
  79. params.require(:pay).permit(:cliente_id, :numero, :fecha, :estado, tickets_attributes: [:id, :pay_id, :total ])
  80. end
  81.  
  82.  
  83. end
Add Comment
Please, Sign In to add comment