stimulate()directly from inside of a Stimulus controller, StimulusReflex maps your requests to Reflex classes on the server. These classes are found in
app/reflexesand they inherit from
testmethod in the Example Reflex class. We refer to Reflex class methods which get called from the client as "Reflex Action methods".
sessionobject, and if you're using the (default) Page Morph Reflexes, any instance variables that you set in your Reflex Action method will be available to the controller action before your page is re-rendered.
current_useror equivalent accessor inside your Reflex actions. First, you'll need to make sure that your Connection is "identified" by your
current_user. Since ActionCable is separate from the ActionController namespace, accessors need to be setup as part of your authentication process.
session_idbefore they authenticate, and then switch over to
identified_by :current_user, you can delegate
current_userto your ActionCable Connection:
current_userfrom all of your Reflex classes, delegate it your ApplicationReflex:
identified_byaccessors such as
current_user, it's important to remember that any ActiveRecord queries or associations you access will be cached by default, even across multiple Reflexes.
connection- the ActionCable connection
channel- the ActionCable channel
ActionDispatch::Requestproxy for the socket connection
ActionDispatch::Sessionstore for the current visitor
ActionDispatch::Flash::FlashHashfor the current request
url- the URL of the page that triggered the reflex
ActionController::Parametersof the closest form
element- a Hash like object that represents the HTML element that triggered the reflex
reflex_id- a UUIDv4 that uniquely identies each Reflex
elementproperty contains all of the Stimulus controller's DOM element attributes as well as other properties like
value. In addition,
datasetproperty reference special collections as described below.
elementproperty and the
datasetcollection in your Reflex action. You can use the dot notation as well as string and symbol accessors.
elementaccessor on every Reflex has two dynamic accessors,
unsignedwhich automatically unpack Global IDs stored in data attributes and converts them to model instances.
rescue_fromto respond to an errors raised.