Forum: Ruby on Rails Problem creating new record

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chetan Thapliyal (Guest)
on 2006-05-09 13:55
(Received via mailing list)
Hi

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'
        script/server:51

        Request

        Parameters: {"device"=>{"name"=>"asdfsa",
"description"=>"dfasdfasdf", "device_category"=>"3", "model"=>"asdf"},
"commit"=>"Create"}


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

20  def create
21    @device = Device.new(params[:device])
22   23      if @device.save
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.

Regards
Chetan

--
Srijan Technologies Pvt. Ltd.
304 Bakshi House,
40-41 Nehru Place,
New Delhi - 110019
INDIA
Ph: 91-11-2622 5926/ 5931
Fax: 91-11-5160 8543
Email: removed_email_address@domain.invalid
Web: www.srijan.in
----------------------
See our Typo3 demos at: http://demos.srijansoft.com
This topic is locked and can not be replied to.