Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is one of my Web app's method.
- class Session < ActiveResource::Base
- def authenticate
- if username.present? && password.present?
- # I want to send request to API and get response from there only.
- @session ||= Session.create(username: self.username, password: self.password, host_: self.host_)
- @username = @session.username # Because we allow login via email, set the username again with response
- end
- @session
- rescue Execption => error
- message = JSON.parse(error.response.body)['message']
- errors.add(:session, message)
- @session = nil
- end
- end
- # API endpoint for Session
- class SessionsController < ApplicationController
- def create
- # My code to authenticate the request and repond accordingly.
- # param => {"controller"=>"/sessions", "action"=>"create", "format"=>"json", "session"=>{}}
- # As you see params["session"] is empty hash but it should contains the parameters those are sending from Web app.
- # Is something I'm doing wrong?
- # Because I need to send request to API and get response from there only
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement