File: accessible_params_wrapper.rb

package info (click to toggle)
ruby-protected-attributes 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 304 kB
  • ctags: 382
  • sloc: ruby: 1,977; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'active_support/concern'
require 'action_controller'
require 'action_controller/metal/params_wrapper'

module ActionController
  module ParamsWrapper
    class Options # :nodoc:
      def include
        return super if @include_set

        m = model
        synchronize do
          return super if @include_set

          @include_set = true

          unless super || exclude

            if m.respond_to?(:accessible_attributes) && m.accessible_attributes(:default).present?
              self.include = m.accessible_attributes(:default).to_a
            elsif m.respond_to?(:attribute_names) && m.attribute_names.any?
              self.include = m.attribute_names
            end
          end
        end
      end
    end
  end
end