I have checked for method/association name clashes and can't see any.
Any tips on how I might debug this further would be very much
appreciated - I am completely stuck!

To recap, I am getting the error "undefined method `each' for
true:TrueClass" when an Active Record method (in active_record/base.rb
- see below) is being executed. So I assume 'attribute_names' is being
set to true for some reason.

      # Returns a copy of the attributes hash where all the values
have been safely quoted for use in
      # an SQL statement.
      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)) &&
(include_primary_key || !column.primary)
            value = read_attribute(name)

            # We need explicit to_yaml because quote() does not
properly convert Time/Date fields to YAML.
            if value && self.class.serialized_attributes.has_key?
(name) && (value.acts_like?(:date) || value.acts_like?(:time))
              value = value.to_yaml
            end

            quoted[name] = connection.quote(value, column)
          end
        end
        include_readonly_attributes ? quoted :
remove_readonly_attributes(quoted)
      end

On 20 Dec, 14:26, Frederick Cheung <frederick.che...@gmail.com> wrote:
> On Dec 20, 1:52 pm, 
> "lee.longm...@googlemail.com"<lee.longm...@googlemail.com> wrote:
> > To add, I am seeing the following when I retrieve an existing Root
> > object in the Rails console and then try to save it again:
>
> My guess would be that you have a method or an association with a name
> that has since been used internally by activerecord. If you can show
> more of your model someone might be able to spot the troublemaker.
>
> Fred
>
> > => #<Root id: 1, type: "Root", name: "Base of Administrator",
> > yaml_container: nil, parent_id: nil, owner_id: 1, custodian_id: 1,
> > property_control_id: 1, include_parent_responses: false, inheritable:
> > false, response_vehicle_id: nil, acquire_child_values: false,
> > description: nil, rating: nil, link_base_id: nil, base_image_id: nil,
> > event_when_id: nil, event_description_id: nil>>> root.save
>
> > NoMethodError: undefined method `each' for true:TrueClass
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > base.rb:2808:in `attributes_with_quotes'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > base.rb:2706:in `update_without_lock'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > locking/optimistic.rb:70:in `update_without_dirty'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > dirty.rb:146:in `update_without_callbacks'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > callbacks.rb:253:in `update_without_timestamps'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > timestamp.rb:38:in `update'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > base.rb:2699:in `create_or_update_without_callbacks'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > callbacks.rb:222:in `create_or_update'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > base.rb:2383:in `save_without_validation'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > validations.rb:1009:in `save_without_dirty'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > dirty.rb:79:in `save_without_transactions'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:179:in `send'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:179:in `with_transaction_returning_status'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > connection_adapters/abstract/database_statements.rb:66:in
> > `transaction'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:129:in `transaction'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:138:in `transaction'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:178:in `with_transaction_returning_status'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:146:in `save'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:158:in `rollback_active_record_state!'
> >         from 
> > /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
> > transactions.rb:146:in `save'
>
> > Any thoughts much appreciated.
>
> > On 20 Dec, 06:54, "lee.longm...@googlemail.com"
>
> > <lee.longm...@googlemail.com> wrote:
> > > I have been working through an upgrade of my 1.2.6 application to
> > > 2.2.2.
>
> > > I am almost there but I have hit a problem with ActiveRecord.
>
> > > Before the upgrade, the following code was working fine.
>
> > >     def create_root(administrator)
> > >         root = create_root_collection(self.pingee_name,
> > >                                       administrator,
> > >                                       GlobalAccessibility.new,
> > >                                       OwnerAccessibility.new)
> > >         root.save
> > >         self.root = root
> > >     end
>
> > > But now I get am getting an exception "undefined method `each' for
> > > true:TrueClass" when root.save is executed.
>
> > > fyi, the "create_root_collection" method creates a "root" object and
> > > assigns new object to its "belongs to" association.
>
> > > I have traced it through carefully and it is definitely failing when
> > > trying to save the "root" object itself.
>
> > > Given the error message, and the fact that the root object contains
> > > boolean columns, I wonder if the problem is to do with the saving
> > > boolean values. I am using MySQL and declaring the boolean columns in
> > > the following way (using raw SQL not migrations currently):
>
> > > include_parent_responses boolean default false not null,
>
> > > Is the "boolean" column type still valid?
>
> > > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to