I’m building a simple website generator application in Rails 3.0. I’d like a “publish” action in a controller that works just like an ordinary “show” action, but instead, saves a page as an HTML file in the “public” directory instead of displaying it in the browser. That is, I’d like to use the Rails render mechanism to create a file instead of providing an HTTP response.
What’s the best way to do this?
Should I simply add caches_page :publish to the controller?
Or use render_to_string and File.new?
I found that page caching using
caches_pagewon’t work for me because there is no way to show a notification or redirect to another page after caching the page. The methodrender_to_string(suggested by @Grocery) is the way to go. Here’s the example controller code: