lib/compony/components/new.rb in compony-0.0.5 vs lib/compony/components/new.rb in compony-0.0.6
- old
+ new
@@ -17,13 +17,14 @@
authorize { can?(:create, data_class) }
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
store_data # This enables the global store_data block defined below for this path and verb.
respond do
if @create_succeeded
- evaluate_with_backfire(&@on_created_block)
+ evaluate_with_backfire(&@on_created_block) if @on_created_block
+ evaluate_with_backfire(&@on_created_respond_block)
else
- evaluate_with_backfire(&@on_create_failed_block)
+ evaluate_with_backfire(&@on_create_failed_respond_block)
end
end
end
end
@@ -53,11 +54,11 @@
store_data do
@create_succeeded = @data.save
end
- on_created do
+ on_created_respond do
flash.notice = I18n.t('compony.components.new.data_was_created', data_label: data.label)
redirect_to evaluate_with_backfire(&@on_created_redirect_path_block)
end
on_created_redirect_path do
@@ -66,28 +67,34 @@
else
Compony.path(:index, @data)
end
end
- on_create_failed do
+ on_create_failed_respond do
Rails.logger.warn(@data&.errors&.full_messages)
render_standalone(controller, status: :unprocessable_entity)
end
end
# DSL method
+ # Sets a block that is evaluated with backfire in the successful case after storing, but before responding.
def on_created(&block)
@on_created_block = block
end
# DSL method
+ def on_created_respond(&block)
+ @on_created_respond_block = block
+ end
+
+ # DSL method
def on_created_redirect_path(&block)
@on_created_redirect_path_block = block
end
# DSL method
- def on_create_failed(&block)
- @on_create_failed_block = block
+ def on_create_failed_respond(&block)
+ @on_create_failed_respond_block = block
end
end
end
end