Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
11/28/07 20:13:17 (2 years ago)
Author:
bitsweat
Message:

attr_protected and _accessible use sets of strings instead of arrays of symbols internally. Closes #10300.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/base.rb

    r8230 r8231  
    629629      # To start from an all-closed default and enable attributes as needed, have a look at attr_accessible. 
    630630      def attr_protected(*attributes) 
    631         write_inheritable_array("attr_protected", attributes - (protected_attributes || [])) 
     631        write_inheritable_attribute("attr_protected", Set.new(attributes.map(&:to_s)) + (protected_attributes || [])) 
    632632      end 
    633633 
     
    663663      #   customer.credit_rating # => "Average" 
    664664      def attr_accessible(*attributes) 
    665         write_inheritable_array("attr_accessible", attributes - (accessible_attributes || [])) 
     665        write_inheritable_attribute("attr_accessible", Set.new(attributes.map(&:to_s)) + (accessible_attributes || [])) 
    666666      end 
    667667 
     
    20852085            attributes.reject { |key, value| attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) } 
    20862086          elsif self.class.protected_attributes.nil? 
    2087             attributes.reject { |key, value| !self.class.accessible_attributes.include?(key.gsub(/\(.+/, "").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) } 
     2087            attributes.reject { |key, value| !self.class.accessible_attributes.include?(key.gsub(/\(.+/, "")) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) } 
    20882088          elsif self.class.accessible_attributes.nil? 
    2089             attributes.reject { |key, value| self.class.protected_attributes.include?(key.gsub(/\(.+/,"").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) } 
     2089            attributes.reject { |key, value| self.class.protected_attributes.include?(key.gsub(/\(.+/,"")) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) } 
    20902090          else 
    20912091            raise "Declare either attr_protected or attr_accessible for #{self.class}, but not both."