Odd behavior on update

If I have the following two legacy data tables:

CREATE TABLE `statusactivities` (   `id` int(11) NOT NULL auto_increment,   `activity` int(11) NOT NULL default '0' )

CREATE TABLE `activities` (   `id` int(11) NOT NULL auto_increment,   `activity` varchar(60) NOT NULL default '' )

And thus, the two models:

class Statusactivity < ActiveRecord::Base   set_table_name 'statusactivities'   belongs_to :activity, :foreign_key => 'activity' end

class Activity < ActiveRecord::Base   set_table_name 'activities'   has_many :statusactivities, :foreign_key => 'activity' end

and I go to update a Statusactivity, I get the following exception. Please note at the bottom, the parameters -- it doesn;t appear to be anything wrong here to me. Can someone please enlighten me as to what I may have specified wrong here that I am unable to update a record here? (I am using scaffolding_extensions btw) - Ralph Vince

ActiveRecord::AssociationTypeMismatch in CrudController#update_statusactivity

Activity expected, got String

C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:134:in `raise_on_type_mismatch' C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/belongs_to_association.rb:22:in `replace' C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:850:in `activity=' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:344:in `send' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:344:in `update_scaffold_attributes' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:343:in `each' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:343:in `update_scaffold_attributes' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:985:in `update_statusactivity' C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `send'

Request

Parameters: {"commit"=>"Update statusactivity", "id"=>"1", "statusactivity"=>{"activity"=>"1"}}

and I go to update a Statusactivity, I get the following exception.

The problem is when you are doing the above activity, can you post the code?

thanks, andy

There isn;t any other than the model descriptions above -- the rest is handled by scaffolding_extensions plugin. -Ralph

You can't have your belongs_to association have the same name as your foreign key. Change the foreign key to activity_id or rename the belongs_to association.

Jeremy