Error, got String?

I am getting this error.

ActiveRecord::AssociationTypeMismatch in Resources#create

Focus expected, got String

I have a select menu named resource[focus]. My focus (belongs_to
:resources) table has a one-to-many relationship with the resources
(has_one :focus) table (A resource will have only one focus but one
focus will have many resources). I assume this error means that the
focus is looking for a string (I am sending an integer, focus_id). What
do I do?

Thanks.

Seth B.

Okay. I figured out that my relationship association was messed up
(resources: belongs_to :focus and focus: has_many :resources) but I
still get the same error.

Seth B. - KATE wrote:

Okay. I figured out that my relationship association was messed up
(resources: belongs_to :focus and focus: has_many :resources) but I
still get the same error.

I decided to see what would happen if I used the console and here is
what I found out.

I start the console:

ruby script/console

resource = Resource.new()

resource.focus = 1

THEN I GET THE ERROR: Focus Expected, got Fixnum

If I put resource.focus = ‘1’ or “1” I get.

Focus Expected, got String.

What is it wanting?

On 21/02/06, Seth B. - KATE [email protected] wrote:

ruby script/console

What is it wanting?

It simply wants Focus :slight_smile: Try:

resource.focus = Focus.new

and this:

resource.focus_id = 1

Use resource[focus_id] in view.