app/controllers/crud_controller.rb in dry_crud-3.0.0 vs app/controllers/crud_controller.rb in dry_crud-5.0.0
- old
+ new
@@ -20,12 +20,10 @@
# Defines before callbacks for the render actions. A virtual callback
# unifiying render_new and render_edit, called render_form, is defined
# further down.
define_render_callbacks :show, :new, :edit
- hide_action :run_callbacks
-
before_action :entry, only: [:show, :new, :edit, :update, :destroy]
helper_method :entry, :full_entry_label
############## ACTIONS ############################################
@@ -55,16 +53,16 @@
# this action and call super with a block that gets the format and
# success parameters. Calling a format action (e.g. format.html)
# in the given block will take precedence over the one defined here.
#
# Specify a :location option if you wish to do a custom redirect.
- def create(options = {}, &block)
+ def create(options = {}, &_block)
assign_attributes
created = with_callbacks(:create, :save) { entry.save }
respond_to do |format|
- block.call(format, created) if block_given?
+ yield(format, created) if block_given?
if created
format.html { redirect_on_success(options) }
format.json { render :show, status: :created, location: show_path }
else
format.html { render :new }
@@ -89,16 +87,16 @@
# this action and call super with a block that gets the format and
# success parameters. Calling a format action (e.g. format.html)
# in the given block will take precedence over the one defined here.
#
# Specify a :location option if you wish to do a custom redirect.
- def update(options = {}, &block)
+ def update(options = {}, &_block)
assign_attributes
updated = with_callbacks(:update, :save) { entry.save }
respond_to do |format|
- block.call(format, updated) if block_given?
+ yield(format, updated) if block_given?
if updated
format.html { redirect_on_success(options) }
format.json { render :show, status: :ok, location: show_path }
else
format.html { render :edit }
@@ -117,15 +115,15 @@
# this action and call super with a block that gets format and
# success parameters. Calling a format action (e.g. format.html)
# in the given block will take precedence over the one defined here.
#
# Specify a :location option if you wish to do a custom redirect.
- def destroy(options = {}, &block)
+ def destroy(options = {}, &_block)
destroyed = run_callbacks(:destroy) { entry.destroy }
respond_to do |format|
- block.call(format, destroyed) if block_given?
+ yield(format, destroyed) if block_given?
if destroyed
format.html { redirect_on_success(options) }
format.json { head :no_content }
else
format.html { redirect_on_failure(options) }
@@ -202,16 +200,20 @@
I18n.t(keys.shift, model: full_entry_label, default: keys)
end
# A label for the current entry, including the model name.
def full_entry_label
+ # rubocop:disable Rails/OutputSafety
"#{models_label(false)} <i>#{ERB::Util.h(entry)}</i>".html_safe
+ # rubocop:enable Rails/OutputSafety
end
# Html safe error messages of the current entry.
def error_messages
+ # rubocop:disable Rails/OutputSafety
escaped = entry.errors.full_messages.map { |m| ERB::Util.html_escape(m) }
escaped.join('<br/>').html_safe
+ # rubocop:enable Rails/OutputSafety
end
# Class methods for CrudActions.
class << self
# Convenience callback to apply a callback on both form actions