keybored
keybored

Reputation: 5248

Automatically generate html file from an erb file using Ruby on Rails

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.

Upvotes: 1

Views: 1848

Answers (2)

Pablo B.
Pablo B.

Reputation: 1833

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.

Upvotes: 0

fl00r
fl00r

Reputation: 83680

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

Upvotes: 1

Related Questions