Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # This is one of my Web app's method.
  2. class Session < ActiveResource::Base
  3. def authenticate
  4. if username.present? && password.present?
  5. # I want to send request to API and get response from there only.
  6. @session ||= Session.create(username: self.username, password: self.password, host_: self.host_)
  7. @username = @session.username # Because we allow login via email, set the username again with response
  8. end
  9. @session
  10. rescue Execption => error
  11. message = JSON.parse(error.response.body)['message']
  12. errors.add(:session, message)
  13. @session = nil
  14. end
  15. end
  16.  
  17.  
  18. # API endpoint for Session
  19.  
  20. class SessionsController < ApplicationController
  21. def create
  22. # My code to authenticate the request and repond accordingly.
  23. # param => {"controller"=>"/sessions", "action"=>"create", "format"=>"json", "session"=>{}}
  24. # As you see params["session"] is empty hash but it should contains the parameters those are sending from Web app.
  25. # Is something I'm doing wrong?
  26. # Because I need to send request to API and get response from there only
  27. end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement