-
Notifications
You must be signed in to change notification settings - Fork 330
Update Action Flow
These methods are called in the following order:
-
update_authorized_filter
called as before_action-
update_authorized?
(or the method defined in conf.update.link.security_method if it's changed) is called to check the permission. If this method returns false,update_authorized_filter
will raise ActiveScaffold::ActionNotAllowed.
-
-
edit
-
do_edit
which usesfind_if_allowed
to load the record to be edited into @record instance variable, checking :update permission. -
respond_to_action
, which will call the corresponding response method for edit action and the requested format
-
do_edit
can be overrided, for example to change some attributes, or set form_ui for some columns depending on values of the edited record, or params of the request.
Then it will render these views:
- update.html.erb (only for HTML request)
- _update_actions.html.erb (only for HTML request, if config.update.nested_links)
- _update_form.html.erb
- _base_form.html.erb
- _form_messages.html.erb
- _messages.html.erb (only for HTML request)
- _form.html.erb
- footer_extension partial if _base_form was called with this variable
- _form_messages.html.erb
- _base_form.html.erb
The _form
partial will render other partials depending on the columns, such as partials to render subforms, or partials for columns which have a partial form override.
The _update_form
partial can be overrided and call render :super with local variables, to change some of default behaviour of _base_form:
- xhr: to force rendering as XHR request or HTML request instead of relying on the value of request.xhr?
- form_action: to use other action in the controller instead of
update
. - method: to use other HTTP method instead of PATCH.
- cancel_link: use false to avoid adding a cancel link to the form.
- headline: to change the header of the form.
The _base_form
partial can be overrided to render :super setting some variables to change the default behaviour, although it's used by many actions. Also, _create_form
partial can be overrided copying the code, and passing more variables to _base_form
. The following variables can be used, besides the ones explained above:
- multipart: to enable or disable rendering the form as multipart instead of relying in
active_scaffold_config.update.multipart
. - persistent: can be
:optional
,true
orfalse
, instead of relying inactive_scaffold_config.update.persistent
. - columns: an ActionColumns instance to use instead of
active_scaffold_config.update.columns
, build it withactive_scaffold_config.build_action_columns :update, [<list of columns>]
. - footer_extension: to render a partial after footer buttons, inside the p tag with class form-footer.
- url_options: to change URL to submit the form, instead of default
params_for(action: :update)
. - scope: to render the fields with an initial scope.
- floating_footer: to enable or disable the floating footer when form is too big to fit in the window, instead of relying on
active_scaffold_config.update.floating_footer
. - submit_text: the text of submit button, which defaults to the value of
form_action
(update with default form_action). - apply_text: the text of submit button which doesn't close the form, when persistent is enabled. The default value is
#{form_action}_apply
(update_apply with default form_action). - body_partial: to use a different partial to render the fields in the form, instead of default
_form
partial.
When form is submitted, these methods are called in the following order:
-
update_authorized_filter
called as before_action-
update_authorized?
(or the method defined in conf.update.link.security_method if it's changed) is called to check the permission. If this method returns false,update_authorized_filter
will raise ActiveScaffold::ActionNotAllowed.
-
-
update
-
do_update
.-
do_edit
which usesfind_if_allowed
to load the record to be edited into @record instance variable, checking :update permission. -
update_save
, which accepts named argumentattributes
which defaults toparams[:record]
, and named argumentno_record_param_update
which can be used to prevent assigning values from attributes argument into @record, e.g. if the changes have been set in other way before.-
update_record_from_params
to set the submitted values fromattributes
argument, unless is called withtrue
inno_record_param_update
. -
before_update_save
will be called, an empty method which can be overrided to set other values before updating the record. - It will run validations in the model and its associations which have been set from the submitted params. The method will stop here if validations fail.
- It will save the record and its associations which have been set.
-
after_update_save
will be called, an empty method which can be overrided to do something after updating a record.
-
-
-
respond_to_action
, which will call the corresponding response method for update action and the requested format- For HTML request:
- If record is saved successfully, it will call
return_to_main
which redirects tomain_path_to_return
, which defaults to list, or render the update form as edit action does if persistent is used. - If record fails to be created, it will render the update form with
update
view, as edit action does.
- If record is saved successfully, it will call
- For XHR request will render
on_update
view.
- For HTML request:
-