Archive for April 17th, 2008

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

Add comment April 17th, 2008


Recommended

Posts by Category

Calendar

April 2008
S M T W T F S
« Mar   May »
 12345
6789101112
13141516171819
20212223242526
27282930  

Posts by Month