Class: Compony::Components::Edit

Inherits:
WithForm show all
Includes:
Compony::ComponentMixins::Resourceful
Defined in:
lib/compony/components/edit.rb

Overview

This component is used for the Rails edit and update paradigm. Performs update when the form is submitted.

Instance Attribute Summary

Attributes included from Compony::ComponentMixins::Resourceful

#data, #global_after_assign_attributes_block, #global_after_load_data_block, #global_assign_attributes_block, #global_load_data_block, #global_store_data_block

Attributes inherited from Compony::Component

#comp_opts, #content_blocks, #parent_comp

DSL collapse

Methods included from Compony::ComponentMixins::Resourceful

#after_assign_attributes, #after_load_data, #assign_attributes, #data_class, #initialize, #load_data, #resourceful?, #store_data

Methods inherited from WithForm

#form_cancancan_action, #form_comp, #form_comp_class, #initialize, #submit_path, #submit_verb

Methods inherited from Compony::Component

#before_render, comp_name, #content, #exposed_intents, family_name, #id, #id_path, #id_path_hash, #initialize, #inspect, #param_name, #path, #remove_content, #remove_content!, #render, #resourceful?, #root_comp, #root_comp?, setup, #sub_comp

Instance Method Details

#on_update_failed { ... } ⇒ void

This method returns an undefined value.

DSL method Overrides the response issued when the update failed (@update_succeeded is not true). The default logs the errors with level warn and re-renders the component with HTTP 422 so the form shows errors.

Yields:

  • Runs in the component's request context; expected to render or redirect.



132
133
134
# File 'lib/compony/components/edit.rb', line 132

def on_update_failed(&block)
  @on_update_failed_block = block
end

#on_updated { ... } ⇒ void

This method returns an undefined value.

DSL method Sets an optional hook evaluated (with backfire) after a successful update but before responding. Suitable for post-update side effects (like an after_update that only fires when this component updated the record). Do not redirect or render here - use #on_updated_respond / #on_updated_redirect_path for that.

Yields:

  • Runs in the component's request context after @data was saved successfully.



102
103
104
# File 'lib/compony/components/edit.rb', line 102

def on_updated(&block)
  @on_updated_block = block
end

#on_updated_redirect_path { ... } ⇒ void

This method returns an undefined value.

DSL method Overrides the redirect target used by the default #on_updated_respond (keeping the default flash). Defaults to the data's Show, the owner's Show, or the data's Index.

Yields:

  • Runs in the component's request context; expected to return a Rails path (e.g. via Compony.path).



122
123
124
# File 'lib/compony/components/edit.rb', line 122

def on_updated_redirect_path(&block)
  @on_updated_redirect_path_block = block
end

#on_updated_respond { ... } ⇒ void

This method returns an undefined value.

DSL method Overrides the response issued after a successful update. The default shows a flash and redirects to #on_updated_redirect_path. If you override this, #on_updated_redirect_path is no longer called.

Yields:

  • Runs in the component's request context; expected to render or redirect.



112
113
114
# File 'lib/compony/components/edit.rb', line 112

def on_updated_respond(&block)
  @on_updated_respond_block = block
end