# Error, got String?

**URL:** <https://www.ruby-forum.com/t/error-got-string/71297>\
**Category:** Rails\
**Created:** [February 21, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/error-got-string/71297 "2006-02-21T16:20:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/error-got-string/71297/1 "2006-02-21T16:20:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 4:50pm UTC](https://www.ruby-forum.com/t/error-got-string/71297/2 "2006-02-21T16:50:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/error-got-string/71297/3 "2006-02-21T16:52:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/error-got-string/71297/4 "2006-02-21T20:42:09Z")

</div>

On 21/02/06, Seth B. - KATE [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # ruby script/console
> 
> What is it wanting?

It simply wants Focus 🙂 Try:

# resource.focus = Focus.new

and this:

# resource.focus\_id = 1

Use resource[focus\_id] in view.
