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.
textis given, the default text "Are you sure?" will be used.
failureevents, it will be emitted regardless of the server response.
200HTTP status code.
500HTTP status codes.
idattribute, like so:
classattribute, like so:
:foo => 'bar'in the params.
:id => '42'to the route we have defined!
app/controllers/action_test_controller.rbto see what the endpoints do:
action_configsuccess message and will get re-rendered.
good job!message that was initially hidden and disappears again after 300ms.
failure_action_test_pathto see how we can notify the user if things go wrong!
localhost:3000/action_test/page1and see our first page, shown by the
This is Page 1text.
Click me!) and get transfered to the second page. There, we see the
This is Page 2text and, for 300ms, our
server says: good job!success message. Neat!
Click me!) on the second page, we get the failure message (
server says: something went wrong!) and get sent back to page 2, just as we wanted to.