action
component can be used to trigger asynchronous requests from - for example a button click - or any other html markup. The action
components let's us wrap content in an a
tag 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.text
is given, the default text "Are you sure?" will be used.sucsess
or failure
events, it will be emitted regardless of the server response.emit
attribute.200
HTTP status code.failure
configuration.400
or 500
HTTP status codes.id
attribute, like so:class
attribute, like so:config/routes.rb
ActionTestController
receives :foo => 'bar'
in the params.config/routes.rb
::id => '42'
to the route we have defined!config/routes.rb
:app/controllers/action_test_controller.rb
to see what the endpoints do:action_config
success message and will get re-rendered.200
:good job!
message that was initially hidden and disappears again after 300ms.failure_action_test_path
to see how we can notify the user if things go wrong!config/routes.rb
:localhost:3000/action_test/page1
and see our first page, shown by the This is Page 1
text.Click me!
) and get transfered to the second page. There, we see the This is Page 2
text 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.