actioncomponent can be used to trigger asynchronous requests from for example a button click or any other html markup. The
actioncomponents let's us wrap content in an
atag which is then clickable and triggers a background request with the configured request method to the configured path and with optionally given params and let's us react to the server response. It can distinguish between a successful and failed response and emit events, transition somewhere, completely redirect and more. You only need to configure it according to your needs.
product_path(product). In the example below, clicking the "Delete" button will trigger an asynchronous DELETE request to the
foo: :bar. If successful the action component will trigger a transition to the path the controller redirected us to. If the request failed it will emit the "deletion-failed" event.
actioncomponents in a method for better readability.
confirm: trueinside the config, the
actioncomponent will show a browser-native confirm dialog before performing the request. When specified, a browser-native confirm dialog is shown before the action is actually performed. The action only is performed after the user confirms. The action is not performed if the user declines to confirm dialog.
actioncomponent by specifiyng the
:failurekey with a hash as value. The value hash can contain different keys for different behavior.
:emitinside it to emit an event for success or failed responses.
:transitionto transition to another page. Either specifiyng a hash containing a path and optional params or a hash with
follow_response: truein order to follow the redirect of the response.
:redirectwith a hash containing a path and params or
follow_response: trueto redirect the browser to the target. Be aware that this will trigger a full website reload as it is a redirect and no transition.
:emitand one of