Problem creating new record


I have two tables
1. devices
2. device_categories

both associated with each other via foreign key device_category_id in
device table. I use scaffold and create a base system. I associate the
two models together via belongs_to declaration in device model, and
has_many declaration in device_categories model. I also add a device
category drop-down box on create page to select required category for
device. Now when I try to create a new device records from front-end I
get the following error message:

    ActiveRecord::AssociationTypeMismatch in Device#create

    DeviceCategory expected, got String

    /app/controllers/device_controller.rb:21:in `create'


    Parameters: {"device"=>{"name"=>"asdfsa",

“description”=>“dfasdfasdf”, “device_category”=>“3”, “model”=>“asdf”},

The given below is the code of device_controller.rb near line 21.

20 def create
21 @device =[:device])
23 if
24 flash[:notice] = ‘Device was successfully created.’
25 redirect_to :action => ‘list’
26 else
27 render :action => ‘new’
28 end
29 end

Thanks in advance of any suggestions to this problem.


Srijan Technologies Pvt. Ltd.
304 Bakshi House,
40-41 Nehru Place,
New Delhi - 110019
Ph: 91-11-2622 5926/ 5931
Fax: 91-11-5160 8543
Email: [email protected]

See our Typo3 demos at:

Chetan Thapliyal wrote:

“description”=>“dfasdfasdf”, “device_category”=>“3”, “model”=>“asdf”},

The method parameter in the select form helper for the device’s category
should be device_category_id rather than device_category.

We develop, watch us RoR, in numbers too big to ignore.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs