Abdelilah
Abdelilah

Reputation: 37

Render an action view into a file in Rails

I'd like to render an action view into a file (or a string it doesn't matter as long as I can write it to a file later), it seems simple enough but I spend many hours on this without success.

Of course we can render a partial or whatever anywhere, but I also need the controller part. So for example, when I go to /mycontroller/myaction I want the rendering to be done into a file (am I making sense ? :)).

Thanks

Upvotes: 2

Views: 1141

Answers (2)

jvnill
jvnill

Reputation: 29599

you're looking for render_to_string method. It accepts all the options you can pass to render but it will return it as a string which you can write to a file.

Upvotes: 3

Dave Newton
Dave Newton

Reputation: 160181

Use render_to_string as per the Rails rendering guide:

http://guides.rubyonrails.org/layouts_and_rendering.html#using-render

Upvotes: 0

Related Questions