Question

I am a newbie to Ruby on rails.... I need advice on how to achieve the below task:

Task: Call api and get JSON data which should be processed for header/footer.haml files. There are api calls for 2 different languages.

concerns: api's should be called only once in a month.

Currently I am doing this: application_controller.rb

before_filter :get_header

require 'rubygems'
require 'json'
require 'httparty'

def get_header
  header_api_response = HTTParty.get('api')
  @res = JSON.parse(header_api_response.body)
end

then I process @res in header.haml file to get the data. But I need this api call function to be called once in a month only. Should I create a cron job outside rails to call this api?? Whats the best solution?

Was it helpful?

Solution

Creating cron will be the best solution for your situation. You may create a cron for that and for using the cron there is a very good and easy to implement gem is available called whenever.

And here is a simple tutorial on how to implement that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top