Class: BeStrong::StrongParameterMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/be_strong/strong_parameter_methods.rb

Defined Under Namespace

Classes: Model

Class Method Summary collapse

Class Method Details

.method_for(name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/be_strong/strong_parameter_methods.rb', line 3

def self.method_for(name)
  model = Model.new(name)
  permits = model.accessible_attributes.map{|attr| ":#{attr}"}.join(', ')
  permit_method = permits.present? ? ".permit(#{permits})" : ''

  <<-"EOS".strip_heredoc
    def #{name}_params
      params.require(:#{name})#{permit_method}
    end
  EOS
rescue NameError
  nil
end