こんな簡単な方法があったとは。
やりたいこと
app/view/papers/show.html.erb の内容を public/static/papers/hogehoge.html に保存したい。
render_to_string を使う
王道は cache_pages を使うみたいだけど、より素朴に render_to_string でできるみたい。(参考:ruby/rails/RailsGuidesをゆっくり和訳してみたよ/Layouts and Rendering in Rails:render の使用(Using render))
def show
File.open("#{Rails.root}/public/static/#{params[:controller]}/hogehoge.html", "w") do |file |
file.puts(render_to_string)
end
endこれで上記のことが可能。