2

I am building an App that serves as the backend for an android app as well as a rails webapp. To serve as a back end, I have built a series of api controllers ( ex: api_users contoller with actions show, update etc.) which will return a JSON/ XML output (using RABL).

In my Webapp, when it is time to update the User profile say, I simply want to call the update action of the api_users controller and parson the json output in my User's controller, parse this output and then handoff the data to my view etc. How do I go about making such calls?

A very bad workaround seems to be to treat it like any external API and call it using Net::Http etc. Can somebody help/ guide me to the recommended way of doing this?

Thanks,

Ramkumar.

asked Feb 23, 2013 at 16:31
7
  • possible duplicate of How do I specify the format for url_for in a nested route? Commented Feb 23, 2013 at 17:41
  • When creating the link with link_to, specify the format option. See the duplicate question for more information. Commented Feb 23, 2013 at 17:41
  • Um...I am not trying to specify a link; I want to use one of my controllers as an API from within my App. So, essentially I want to call an action of a different controller and process the output within my controller action. Commented Feb 23, 2013 at 17:57
  • Calling one controller action from another controller action requires breaking the design of Rails, so it would be a workaround yes. I imagine you would be better off extracting the logic related to updating a profile into the model layer, and use that in both controller actions, or just use a single controller action for both cases. Commented Feb 23, 2013 at 18:11
  • It seems very strange that I should be able to call an external api, but there is no easy way to call my own on the same app. After all, I am not exactly breaking MVC here, all I am asking for is a complete request cycle to be processed. And this is just so that I can avoid repeating myself. Commented Feb 23, 2013 at 19:00

1 Answer 1

0

Since I did not find any simple way to do this, I decided to treat it like an external api. Only instead of going all the way to the dns and back, I decided to simply call it using off of localhost.

answered Feb 24, 2013 at 14:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.