Ruby on Rails: How to get the output from an action (render_component_as_string)
April 17th, 2008
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
Entry Filed under: developers, ruby on rails

Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">
Trackback this post | Subscribe to the comments via RSS Feed