Another Problem with params


#1

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’

My view reads

Department
<% @departments.each do |department_id| %> <%= department_id.department_name %> <% end %>

Sub equipment
<% @subequipments.each do |subequipment| %> <%= 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
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:inbelongs_to_without_reflection’
(eval):5:in belongs_to' #{RAILS_ROOT}/app/models/spare.rb:6 #{RAILS_ROOT}/app/controllers/admin_controller.rb:24:increate’

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