Ruby script that uses rails views?

Hi All,

    I want to write a ruby script that I can launch via a cron job once a night.

    This script would need to access a rails app that've created, it would need to render a xml builder view in the app to text and save the text as a xml file.

    I've already written the rails view and and I have corresponding controller action.

    Is it possible to run a rails controller action from a ruby file and saves its output to a file? Does anyone have any examples of how one might do this? If you can't run a controller action, is there anyway to render a rails view to text from a ruby script?

    Thanks in advance,     Janak

j s wrote:

Hi All,

    I want to write a ruby script that I can launch via a cron job once a night.

    This script would need to access a rails app that've created, it would need to render a xml builder view in the app to text and save the text as a xml file.

    I've already written the rails view and and I have corresponding controller action.

    Is it possible to run a rails controller action from a ruby file and saves its output to a file? Does anyone have any examples of how one might do this? If you can't run a controller action, is there anyway to render a rails view to text from a ruby script?

For running an action from a script take a look at script/runner.

To save the contents of a rendered view to a file you can either turn on caching for that action and grab that resulting view or you can use render_to_string and then save that string to a file explicitly.