class PermittedParams::Attributes
Attributes
attributes[RW]
Public Class Methods
new(permitted_params)
click to toggle source
# File lib/permitted_params.rb, line 45 def initialize(permitted_params) @attributes = [] @permitted_params = permitted_params end
Public Instance Methods
action_is(action_name)
click to toggle source
# File lib/permitted_params.rb, line 86 def action_is(action_name) @permitted_params.params[:action].to_sym == action_name.to_sym end
array(*attrs)
click to toggle source
# File lib/permitted_params.rb, line 54 def array(*attrs) attrs.each do |attr| self.attributes << {attr => []} end end
inherits(*other_attrs)
click to toggle source
# File lib/permitted_params.rb, line 80 def inherits(*other_attrs) other_attrs.each do |other_attr| self.attributes += @permitted_params.send("#{other_attr}_attributes") end end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/permitted_params.rb, line 90 def method_missing(method, *args, &block) controller = @permitted_params.controller if controller.respond_to? method controller.send(method, *args, &block) else super end end
nested(*attrs_or_options)
click to toggle source
# File lib/permitted_params.rb, line 60 def nested(*attrs_or_options) attrs = attrs_or_options if attrs_or_options.last.is_a? Hash options = attrs_or_options.pop else options = {} end attrs.each do |attr| # attr is like questions or questions_attributes attr = attr.to_s.gsub(/_attributes\z/, '') singular_attr = attr.singularize child_attrs = @permitted_params.send("#{singular_attr}_attributes") child_attrs << :id child_attrs << :_destroy if options[:allow_destroy] self.attributes << {"#{attr}_attributes".to_sym => child_attrs} end end
scalar(*attrs)
click to toggle source
# File lib/permitted_params.rb, line 50 def scalar(*attrs) self.attributes += attrs end