Ruby on Rails: How to get the output from an action (render_component_as_string)

This one took a little bit but I finally figured it out …

@xml = render_component_as_string :controller => “quote”, :action => “xml”, :params => {:request_id => 100}

This would run the action “xml” of the controller “quote” and pass the parameter  “100” to it to do so.

Whatever would have been displayed at /quote/xml/100 is now stored in @xml

This allows you get the output from any action …. anywhere, also allowing you to pass parameters to it in the process.

Even better, this actually runs the action and its view (unlike render :action, which just renders the action view).

For more details, go to the Ruby On Rails Manual > Using components