&Components let you call actions from within a view or from within some other controller. The action will be executed and its results rendered or returned to you as a string.
For example (taken from “Agile Web Development with Rails”) a view template could call a component like this…
;pre>
This executes \StoreController#cart_summary and inserts the rendered results (presumably from …/views/store/cart_summary.rhtml) into the <div> in the middle of the template.
Similarly, your controller can ask another controller to render the display on your behalf. You might do this to include some context-sensitive information in your view – that is, you can only work out what it is you need to show when you get there! Your action munges all the data, sets up all the pre-requisites and then passes control to another controller to let that do the rendering for you.
Of course, you might want to render the results from more than one action from different controllers. In this case you would use render_component_as_string() for each of them and merge the results in your own view.
If you want to pass parameters to your component, do like this:
render_component :controller => “mycomponent”, :action => “myaction”, :params => { “myparam” => “paramvalue” }
See also: