Wednesday, 15 July 2015

ruby on rails - How to show login page based on API response -


I am consuming a Rail API using a client app written in Rail. If the user is not authenticated, then I have to show the login page. I've just created a composition to call API calls from a Ruby class. Now if the response status is 401 from the Ruby class then I have to show the login page. Is there a way to redirect the user to login with Ruby Class?

This is my client code

  class running client df (method, url, params) response = case method when receiving: httparty.get Post (url, query: parameters) when: Post httparty.post (URL, body: params) when: Enter HTTParty.put (URL, body: params) when: Delete HTTParty.delete (url, body: params) else zero If finished, response.status == 401 # will need to redirect the page to login # Send the result to the caller, which will parse it and the controller The action will be sent back which will call it at the end of the end 

end

I resolved this problem by raising a custom exception that I can easily redirect to the login page from the application holding in the controller.

No comments:

Post a Comment