# Getting raise\_on\_type\_mismatch

**URL:** <https://www.ruby-forum.com/t/getting-raise-on-type-mismatch/141581>\
**Category:** Rails\
**Created:** [June 27, 2008, 9:42am UTC](https://www.ruby-forum.com/t/getting-raise-on-type-mismatch/141581 "2008-06-27T09:42:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hemal\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/278dde/32.png) [@Hemal\_M](https://www.ruby-forum.com/u/Hemal_M)\
**Post date:** [June 27, 2008, 9:42am UTC](https://www.ruby-forum.com/t/getting-raise-on-type-mismatch/141581/1 "2008-06-27T09:42:33Z")

</div>

Hello, I am a newbie Ruby developer.

I have an “Bookstore” application consisting of Books Prices.

In the Edit page, I am trying to associate Books with Price. The Books  
and Prices has a has\_one relationship and belongs\_to relationship.

class Book \< ActiveRecord::Base  
belongs\_to :price  
end

class Price \< ActiveRecord:Base  
has\_one :book  
end

table book (  
id int,  
title varchar(20)  
price\_id int  
);

table price (  
id int  
amount float  
);

When I enter the Amount in the Edit page, I get the following  
error:

Price(#-616403668) expected, got String(#-610120718)

/home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/  
active\_record/associations/association\_proxy.rb:214:in  
`raise_on_type_mismatch' /home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/ active_record/associations/belongs_to_association.rb:22:in`replace’  
/home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/  
active\_record/associations.rb:1106:in `price=' /home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/ active_record/base.rb:2361:in`send’  
/home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/  
active\_record/base.rb:2361:in `attributes=' /home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/ active_record/base.rb:2360:in`each’  
/home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/  
active\_record/base.rb:2360:in `attributes=' /home/hemal/src/ruby/rubygems-1.1.1/gems/activerecord-2.1.0/lib/ active_record/base.rb:2261:in`update\_attributes’  
app/controllers/books\_controller.rb:63:in `update' app/controllers/books_controller.rb:62:in`update’

How do I fix the error? Any help will be greatly appreciated,

/hemal.

---

<div class="post-metadata">

**Author:** ![Hemal\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/278dde/32.png) [@Hemal\_M](https://www.ruby-forum.com/u/Hemal_M)\
**Post date:** [June 27, 2008, 10:17am UTC](https://www.ruby-forum.com/t/getting-raise-on-type-mismatch/141581/2 "2008-06-27T10:17:06Z")

</div>

On Jun 27, 2:26 am, Hemal M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class Price \< ActiveRecord:Base  
> has\_one :book  
> end

It looks like you’re trying to assign a string (presumably the value  
entered on your page) to the book’s price which won’t work because  
price= is expecting an instance of Price  
[railscasts.com](http://railscasts.com) has a good series on forms that interact with multiple  
models (although I’m not entirely sure why you need that in this case)  
Fred
