# Ruby script that uses rails views?

**URL:** <https://www.ruby-forum.com/t/ruby-script-that-uses-rails-views/103054>\
**Category:** Rails\
**Created:** [May 1, 2007, 7:18am UTC](https://www.ruby-forum.com/t/ruby-script-that-uses-rails-views/103054 "2007-05-01T07:18:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakattack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@jakattack](https://www.ruby-forum.com/u/jakattack)\
**Post date:** [May 1, 2007, 7:18am UTC](https://www.ruby-forum.com/t/ruby-script-that-uses-rails-views/103054/1 "2007-05-01T07:18:28Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![jakattack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@jakattack](https://www.ruby-forum.com/u/jakattack)\
**Post date:** [May 1, 2007, 7:41am UTC](https://www.ruby-forum.com/t/ruby-script-that-uses-rails-views/103054/2 "2007-05-01T07:41:29Z")

</div>

j s wrote:

> 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.

–  
Michael W.
