| Module | ActionController::Components |
| In: |
vendor/rails/actionpack/lib/action_controller/components.rb
|
Components allows you to call other actions for their rendered response while execution another action. You can either delegate the entire response rendering or you can mix a partial response in with your other content.
class WeblogController < ActionController::Base
# Performs a method and then lets hello_world output its render
def delegate_action
do_other_stuff_before_hello_world
render_component :controller => "greeter", :action => "hello_world", :params => { "person" => "david" }
end
end
class GreeterController < ActionController::Base
def hello_world
render_text "#{@params['person']} says, Hello World!"
end
end
The same can be done in a view to do a partial rendering:
Let's see a greeting: <%= render_component :controller => "greeter", :action => "hello_world" %>
# File vendor/rails/actionpack/lib/action_controller/components.rb, line 27
27: def render_component(options)
28: @controller.send(:render_component_as_string, options)
29: end
Renders the component specified as the response for the current method
# File vendor/rails/actionpack/lib/action_controller/components.rb, line 35
35: def render_component(options = {}) #:doc:
36: component_logging(options) { render_text(component_response(options).body, response.headers["Status"]) }
37: end