Socket
Book a DemoInstallSign in
Socket

render_component_4

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

render_component_4

5.0.0
bundlerRubygems
Version published
Maintainers
3
Created
Source

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

FAQs

Package last updated on 16 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.