Guest User

Untitled

a guest
Nov 6th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class Api::ClientsController < ApplicationController
  2. skip_before_action :verify_authenticity_token
  3. def index
  4. render json: Client.all
  5. end
  6. def show
  7. client = Client.find(params[:id])
  8. render json: client
  9. end
  10. def create
  11. client = Client.new(client_params)
  12. if client.save!
  13. head 200
  14. else
  15. head 500
  16. end
  17. end
  18. private
  19. def client_params
  20. params.require("client").permit(:name, :email, :password, :password_confirmation)
  21. end
  22. end
  23.  
  24. curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"oi", "email":"oi2@gmail.com","password":"123456", "password_confirmation":"123456"}' http://localhost:3000/api/clients
  25.  
  26. Processing by Api::ClientsController#create as JSON
  27. Parameters: {"name"=>"oi", "email"=>"oi2@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "client"=>{"name"=>"oi", "email"=>"oi2@gmail.com"}}
  28. (0.1ms) begin transaction
  29. ↳ app/controllers/api/clients_controller.rb:12
  30. Client Exists (0.3ms) SELECT 1 AS one FROM "clients" WHERE "clients"."email" = ? LIMIT ? [["email", "oi2@gmail.com"], ["LIMIT", 1]]
  31. ↳ app/controllers/api/clients_controller.rb:12
  32. (0.1ms) rollback transaction
  33. ↳ app/controllers/api/clients_controller.rb:12
  34. Completed 422 Unprocessable Entity in 7ms (ActiveRecord: 0.4ms)
  35. ActiveRecord::RecordInvalid (Validation failed: Password can't be blank):
  36. app/controllers/api/clients_controller.rb:12:in `create'
Add Comment
Please, Sign In to add comment