Sha256: 299f3de98af5e72c0d95c639032c239a4528db1f252668ad403e6b07088f8f1a

Contents?: true

Size: 1.65 KB

Versions: 21

Compression:

Stored size: 1.65 KB

Contents

Components allow you to call other actions for their rendered response while executing 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" %>

It is also possible to specify the controller as a class constant, bypassing the inflector
code to compute the controller class at runtime:

<%= render_component :controller => GreeterController, :action => "hello_world" %>

== When to use components

Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and
conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead,
reserve components to those rare cases where you truly have reusable view and controller elements that can be employed
across many applications at once.

So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.

Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
render_component_4-5.0.0 README
render_component_4-4.1.4 README
brisk-bills-0.8.2 vendor/plugins/render_component/README
brisk-bills-0.8.1 vendor/plugins/render_component/README
six-updater-web-0.24.15 lib/six-updater-web/vendor/plugins/render_component/README
six-updater-web-0.24.14 lib/six-updater-web/vendor/plugins/render_component/README
six-updater-web-0.24.13 lib/six-updater-web/vendor/plugins/render_component/README
render_component_vho-3.2.1 README
render_component_vho-3.2.0 README
render_component_vho-3.1.1 README
render_component_vho-3.1.0 README
render_component-3.0.4 README
render_component_vho-3.0.3 README
render_component_vho-3.0.2 README
six-updater-web-0.24.12 lib/six-updater-web/vendor/plugins/render_component/README
six-updater-web-0.24.11 lib/six-updater-web/vendor/plugins/render_component/README
six-updater-web-0.24.10 lib/six-updater-web/vendor/plugins/render_component/README
six-updater-web-0.24.9 lib/six-updater-web/vendor/plugins/render_component/README
render_component-1.0.0 README
brisk-bills-0.7.0 vendor/plugins/render_component/README