Forum: Ruby on Rails Another Problem with params

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.
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
manage...

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'
<snip>

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

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
       C:/InstantRails_1_0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/core_ext/hash/keys.rb:48:in
`assert_valid_keys'
C:/InstantRails_1_0/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:519:in
`belongs_to_without_reflection'
(eval):5:in `belongs_to'
#{RAILS_ROOT}/app/models/spare.rb:6
#{RAILS_ROOT}/app/controllers/admin_controller.rb:24:in `create'

Request

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"=>"",
"cell_number"=>""}}

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
> > >
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>



--
Dattatraya
This topic is locked and can not be replied to.