You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components/action.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,52 @@ class TestModelsController < ApplicationController
105
105
end
106
106
```
107
107
108
+
#### Perform redirect
109
+
110
+
We can also perform a redirect (full page load) that only gets triggered on success and also accepts further params:
111
+
112
+
Please be aware, that emiting a event doen't have an effect when performing a redirect instead of a transition, as the whole page (including the surrounding app) gets reloaded!
113
+
114
+
```ruby
115
+
success: {
116
+
emit:'my_action_success', # doesn't have an effect when using redirect
117
+
redirect: {
118
+
path::action_test_page2_path,
119
+
params: { id:42 }
120
+
}
121
+
}
122
+
```
123
+
124
+
When the server redirects to a url, for example after creating a new record, the redirect needs to be configured to follow this redirect of the server response.
125
+
126
+
```ruby
127
+
success: {
128
+
emit:'my_action_success', # doesn't have an effect when using redirect
129
+
redirect: {
130
+
follow_response:true
131
+
}
132
+
}
133
+
```
134
+
135
+
A controller action that would create a record and then respond with the url the page should redirect to, could look like this:
136
+
137
+
```ruby
138
+
classTestModelsController < ApplicationController
139
+
includeMatestack::Ui::Core::ApplicationHelper
140
+
141
+
defcreate
142
+
@test_model=TestModel.create(test_model_params)
143
+
144
+
render json: {
145
+
redirect_to: test_model_path(@test_model)
146
+
}, status::ok
147
+
end
148
+
end
149
+
```
150
+
151
+
Same applies for the `failure` configuration.
152
+
153
+
108
154
### Failure
109
155
110
156
As counterpart to the success part of the action component, there is also the possibility to define the failure behavior. This is what gets triggered after the response to our action returns a failure code, usually in the range of `400` or `500` HTTP status codes.
0 commit comments