Marcos Alvares
2008-Aug-26 21:04 UTC
[Betternestedset-talk] Bugfix - Overide activerecord method is broken a instance "update"
Hello, First, congratulation for the nice plugin. I''m currently using your plugin for a project on my job. I have discovered a small bug on this method. ################## [/activerecord-2.1.0/lib/active_record/base.rb] def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) quoted = {} connection = self.class.connection attribute_names.each do |name| if column = column_for_attribute(name) quoted[name] = connection.quote(read_attribute(name), column) unless !include_primary_key && column.primary end end include_readonly_attributes ? quoted : remove_readonly_attributes(quoted) end ##################################################################### ############# [/vendor/plugins/betternestedset/lib/better_nested_set.rb] def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true) #:nodoc: left_and_right_column = [acts_as_nested_set_options[:left_column], acts_as_nested_set_options[:right_column]] quoted = attributes.inject({}) do |quoted, (name, value)| if column = column_for_attribute(name) quoted[name] = quote_value(value, column) unless ! include_primary_key && (column.primary || left_and_right_column.include?(column.name)) end quoted end include_readonly_attributes ? quoted : remove_readonly_attributes(quoted) end ############################################################### When this method is call in the creation of a new object instance, its works perfectly, but when i call this for update a instance the active record break. This ocurr because the "attributes_with_quotes" not receive three parameters. With this we cant update any attributes of the instance with update_attributes or other method. #################################################### [ERROR]>> a = EntityGroup.find :first >> a.label = ''mmm''a.save ArgumentError: wrong number of arguments (3 for 2) from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2479:in `attributes_with_quotes'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2479:in `update_without_lock'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/locking/optimistic.rb:70:in `update_without_dirty'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:137:in `update_without_callbacks'' from (irb):5>> ########### Solution: ############# [/vendor/plugins/betternestedset/lib/better_nested_set.rb] def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true, fake_attribute = true) #< PATCH HERE left_and_right_column = [acts_as_nested_set_options[:left_column], acts_as_nested_set_options[:right_column]] quoted = attributes.inject({}) do |quoted, (name, value)| if column = column_for_attribute(name) quoted[name] = quote_value(value, column) unless ! include_primary_key && (column.primary || left_and_right_column.include?(column.name)) end quoted end include_readonly_attributes ? quoted : remove_readonly_attributes(quoted) end ############################################################### Marcos Alvares < marcos[dot]alvares [at] gmail.com>