How to get a controller response from another controller?

Rails 3.2.5 . I have a series of controllers that make up the JSON API that the Backbone.js application consumes. Now I want to create a series of controllers that will serve static content for crawlers / spiders / googlebot. I would like to get the same data from the JSON API, as they are adapted to the descriptor templates that I already use with my Backbone.js application, but this time render them on the server side.

Is there any way I can respond to a JSON response from my API controllers and access them from another controller? . I know I can use curl , but since the JSON API is already local to me and within the same Rails application, is there a more efficient and elegant way?

+7
source share
1 answer

No no. If you need something like this, specify the common code inside another class (you are probably trying to create a service) and then use this in both controllers so you can easily share the code and then generate JSON from the output for both of them.

Given that you use RABL to generate JSON, you should include the fragments that you want to reuse in partial files , and then include them in each of the specific types, like any other types of rails.

+2
source

All Articles