Forum: Ruby on Rails Problem creating new record

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chetan Thapliyal (Guest)
on 2006-05-09 12:20
(Received via mailing list)

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: removed_email_address@domain.invalid
See our Typo3 demos at:
Mark Reginald J. (Guest)
on 2006-05-09 13:00
(Received via mailing list)
Chetan Thapliyal wrote:

> "description"=>"dfasdfasdf", "device_category"=>"3", "model"=>"asdf"},
> "commit"=>"Create"}

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 topic is locked and can not be replied to.