Class: Compony::Components::New

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

Overview

This component is used for the Rails new and create 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_create_failed_respond { ... } ⇒ void

This method returns an undefined value.

DSL method Overrides the response issued when the create failed (@create_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.



120
121
122
# File 'lib/compony/components/new.rb', line 120

def on_create_failed_respond(&block)
  @on_create_failed_respond_block = block
end

#on_created { ... } ⇒ void

This method returns an undefined value.

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

Yields:

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



90
91
92
# File 'lib/compony/components/new.rb', line 90

def on_created(&block)
  @on_created_block = block
end

#on_created_redirect_path { ... } ⇒ void

This method returns an undefined value.

DSL method Overrides the redirect target used by the default #on_created_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).



110
111
112
# File 'lib/compony/components/new.rb', line 110

def on_created_redirect_path(&block)
  @on_created_redirect_path_block = block
end

#on_created_respond { ... } ⇒ void

This method returns an undefined value.

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

Yields:

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



100
101
102
# File 'lib/compony/components/new.rb', line 100

def on_created_respond(&block)
  @on_created_respond_block = block
end