module ActiveComponent
This is an autoincluded module for ActionController::Base
It will store the controller context for the given request in a @@controllers hash.
It was necessary to remove the controller instance from the @@controllers hash manually using ObjectSpace to prevent memory leaks in the server.
You can call ActiveComponent.get_controller
from anywhere in the application.
.
This provides a method camelize and constantize
Autoinclude some of the modules from the controller top level
This provides a clean implementation for rendering your template inside your view.
<%= render_component(:view, var: var) %>
In addition to that you can render a collection of components using the same helper method
<%= render_component(:view, collection: views, as: :view)%>
The :as argument helps you to provide the instance variable name that you defined int your component class and it will be received like that.
Constants
- VERSION
Public Class Methods
# File lib/active_component/context.rb, line 20 def controllers if Rails.env.test? @@controllers else puts "WARNING: ActiveComponent#controllers cannot be accessible from outside of the class" end end
# File lib/active_component/context.rb, line 28 def get_controller @@controllers[Thread.current.object_id] end
# File lib/active_component/context.rb, line 32 def set_controller(controller) @@controllers[Thread.current.object_id] = controller ObjectSpace.define_finalizer Thread.current, lambda { |id| @@controllers[id].delete! } end