Sha256: d054ee5319d94915ea2f1b0d5170c80382b4f3b8b3f78e4412a8637f37125168

Contents?: true

Size: 899 Bytes

Versions: 34

Compression:

Stored size: 899 Bytes

Contents

require "active_support/concern"

module Renalware
  module Concerns::NestedActionsControllerMethods
    extend ActiveSupport::Concern

    included do
      # Allows add and remove form submissions for a nested collection
      #
      # @params
      # nested - the nested collection where items are added or removed
      # default_action - the update or save action wrapped in a proc
      # build_attrs - attributes to pass to collection#build when adding to the collection
      #
      def perform_action(nested, default_action, build_attrs = {})
        if (actions = params[:actions]).present?
          if actions.key?(:remove)
            index = actions[:remove].keys.first.to_i
            nested.destroy(nested[index])
          else
            nested.build(build_attrs)
          end
          false
        else
          default_action.call
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
renalware-core-2.0.15 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.14 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.13 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.12 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.11 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.9 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.8 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.7 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.5 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.4 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.3 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.2 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.1 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/concerns/nested_actions_controller_methods.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/concerns/nested_actions_controller_methods.rb