Hello everyone. I’m having some trouble with calling render_to_string
from a separate controller. I’m also new with using methods from other
controllers, but I think I’ve got a grasp on that.
So here’s what I’m doing:
In controller A:
blah = ControllerB.new
In controller B
mystring = render_to_string :partial => ‘blahblah’
And this is the error I’m receiving:
" NoMethodError in ThingsController#create
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.body
The problem is with the render_to_string being called. I did some
research into erase_render_results, which is called by render_to_string
to apparently clear the output, and prevent DoubleRender errors. You can
see the source (I think) here: http://dev.rubyonrails.org/changeset/1918
So, I believe it’s breaking on the line “@response.body = nil”
Does anybody have any advice about how to use render_to_string in a
controller, being called from a different controller? It’s driving me
crazy, and is starting to seem like a Ruby bug. The code runs fine if
called directly from controller B, but several different controllers
will need to call this method, and I’d like to keep it out of
application.rb if possible.