Using render_to_string in view or helper

I suspect some Google searcher is going to find this useful one day…

In Rails, render_to_string cannot be used in a view or helper, as it’s an ActionController method, not an ActionView method.  Instead, you can use standard render commands.  But beware, using render :file will set the content type header to the type of the file. Rather, read the file into a local variable and use render :inline.

I’ve just confirmed this in Rails 2.2, and I suspect it’s a recent thing, as I don’t believe it always worked this way.

No Comments

Leave a reply