Forum: Ruby on Rails Another Problem with params

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.
Dattatraya G. (Guest)
on 2006-03-22 15:22
(Received via mailing list)
I am trying to do a similar thing for some spares that I am trying to

My spare.rb file is as under

class Spare < ActiveRecord::Base
    belongs_to :department, :class_name => 'department', :foreign_key
=> 'department_id'
   belongs_to :subequipment, class_name => 'subequipment',
:foreign_key => 'sub_equipment'

My view reads
<p><label for="spare_department">Department</label><br/>
 <select name="spare[department_id]">
 <% @departments.each do |department_id| %>
 <option value="<%= %>">
 <%= department_id.department_name %>
 <% end %>
<p><label for="spare_sub_equipment">Sub equipment</label><br/>
<select name="spare[subequipment]">
 <% @subequipments.each do |subequipment| %>
 <option value="<%= %>">
 <%= subequipment.sub_equipment_name %>
 <% end %>

It works fine if I have only one foreign key say department. When I
try to introduce a second one like sub-equipment by adding the line
belongs_to :subequipment, class_name => 'subequipment', :foreign_key
=> 'sub_equipment'

I get the following error
   ArgumentError in   Admin#create  Unknown key(s): Spare

RAILS_ROOT: ./script/../config/..
            Application Trace |            Framework Trace |
 Full Trace
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/controllers/admin_controller.rb:24:in `create'


Parameters: {"commit"=>"Create",  "spare"=>{"nature"=>"C",
"remarks"=>"",  "pattern_number"=>"mbm-50",  "description"=>"akjl",
"subequipment"=>"1",  "equipment"=>"1",  "department_id"=>"1",
"section"=>"1"},  "location"=>{"box_number"=>"",  "compartment"=>"",

Show session dump
flash: !map:ActionController::Flash::FlashHash {}

Response Headers: {"cookie"=>[],  "Cache-Control"=>"no-cache"}

On 3/22/06, Liquid <removed_email_address@domain.invalid> wrote:
> <%= text_field "student", "department_id" %>
> >  Hi,
> > >
> > > the method
> > > new student to the database
> > >

This topic is locked and can not be replied to.