How do I render a partial to a string from within a filter attached to a controller
Posted
by Tristan Havelick
on Stack Overflow
See other posts from Stack Overflow
or by Tristan Havelick
Published on 2010-04-09T22:55:08Z
Indexed on
2010/04/10
15:53 UTC
Read the original article
Hit count: 234
I have some code I need to use in multiple controllers in a rails 1.0 application (I can't, for strange reasons upgrade to a newer rails). I've extracted the relevant code into a filer object, and I'm using the around_filter construct to execute it.
Before the extract, I was using the method render_to_string() to get the contents of a rendered partial into a string. However, this method is protected, so I am unable to access it from within my Filter object. As a workaround, I tried adding this to my ApplicationController:
def render_to_string(*a)
super(*a)
end
this seems to have remedied the protection level issue, but now I get the error:
Can only render or redirect once per action
When no such error occurred before the extraction. Why? Is there a different approach I should take here?
© Stack Overflow or respective owner