Sha256: 36d708bee59036e7b4e624fe1f3b14420e03ffeb6c5db7f9289b231017028d4a

Contents?: true

Size: 766 Bytes

Versions: 7

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

module Cookbook
  # Concern to allow strong parameters when using accepts_nested_attributes_for to edit Cookbook Uses
  module Params
    extend ActiveSupport::Concern

    included do
      # rescue_from Pundit::NotAuthorizedError, with: :authorization_error
      # include Pundit
    end

    def cookbook_params(model_name)
      model = model_name.constantize

      attributes = {}
      model.used_in.each do |table_sym|
        singular = table_sym.to_s.singularize
        attribute_sym = "#{singular}_uses_attributes".to_sym
        attributes[attribute_sym] = %i[
          id _destroy use_of_type use_of_id quantity_minimum quantity_maximum unit preparation note sort
        ]
      end
      attributes
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cookbook-0.1.6 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.5 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.4 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.3 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.2 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.1 app/controllers/concerns/cookbook/params.rb
cookbook-0.1.0 app/controllers/concerns/cookbook/params.rb