Calling render_to_string from a separate controller

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 =

  • In controller B
    def doStuff

    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

erase_render_results' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:788:inrender_to_string’
update_profile' #{RAILS_ROOT}/app/controllers/things_controller.rb:43:increate’

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:

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.


Any luck with this? I’m running into the same issue.


On Dec 5, 12:49 am, Jared S. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs