Rails 3.2.5. I have a series of controllers that make up a JSON API which my Backbone.js application consumes. I am now looking to create a series of controllers that will serve static content to crawlers/spiders/googlebot. I would like to get the same data from the JSON API since they are tailored to the handlebars templates I already use with my Backbone.js application but this time render them server-side.
Is there a way that I can take the 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 are more efficient and elegant way?
No, there isn't. If you need something like this, factor the shared code inside another class ( you are probably trying to build a service ) and then use this in both controllers so you can easily share the code and then generate the JSON from the output for both of them.
Given you are using RABL for JSON generation, you should turn the pieces you want to reuse into partials and then include them in each of the specific views, just like any other rails view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With