1

I have a RoR app that tracks the status of values in a database and displays the visualization of this information in the form of charts, graphs, and tables generated by an erb file. This is very handy and I am able to save snapshots of the status' of the DBs by simply saving the page when I open it in a browser. What I would like, however, is for my app to automatically do this saving for me on a nightly basis. I assume this is possible but I'm not having much luck with this so far. Any suggestion on this point would be very helpful.

2
  • are these charts and graphs generated dynamically from the single HTML? if they are separate files then solution will be more complicated because you will have to save more files Commented Mar 30, 2011 at 20:04
  • Yes they are, I have graphs that are built using google's chart tools. I simply have the url's in the erb file and I fill out the important bits with information pulled from the DB. Commented Mar 31, 2011 at 16:15

2 Answers 2

1

you can always use render_to_string method to render your erb. For example you need to render show.html.erb for show action in statistics controller:

 my_page = render_to_string :controller => 'statistics', :action => 'show', :layout => 'application'

but firstly you should define all it's variables which you use int show view.

@data = Data.last_data
@users = User.active
enter code here
my_page = render_to_string :controller => 'statistics', :action => 'show', :layout => 'application'
snapshot = Snapshot.new :page => my_page
snapshot.save

API: http://apidock.com/rails/ActionController/Base/render_to_string

Sign up to request clarification or add additional context in comments.

1 Comment

This does not work anymore. render_to_string is defined in ActionController::Base. Since the class/module is defined outside the scope of the Rails controllers the function is not available.
0

You can use whenever: https://github.com/javan/whenever

From the readme:

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

There is also delayed-job: https://github.com/tobi/delayed_job

From the Readme:

Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background.

1 Comment

Ultimately ended out writing straight-up cron jobs in the manner expected by the Heroku cron add-on. (devcenter.heroku.com/articles/cron) Looking at my posting I now see that I didn't mention that I was deploying to Heroku at all, oops. Whenever worked well for our internal testing though.

Your Answer

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.