Re: Nested attributes (unknown attribute error)-overiding default foreign key referencing

Colin Law
Fri, 08 Feb 2013 12:30:52 -0000

On 8 February 2013 11:00, poornima c.
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:
> Am getting the following error in ruby on rails:
> ActiveRecord::UnknownAttributeError in AWRequestsController#new unknown
> attribute: a_w_request_id.
>
> I have a form that is tied to two models.
>
> a_w_request.rb:
>
> class AWRequest <ActiveRecord::Base
>     set_primary_key : request_id
>     set_table_name: w_r_details
>     attr_accessible : request_id,
> :requester_contact,:needed_by,:w_a_details_attributes
>
>     has many: w_a_details, :dependent => :destroy
>
>     accepts_nested_attributes for :w_a_details, :allow_destroy => :true
>     :reject_if => proc {|attrs| attrs.all? {|k,v| v.blank? } }
> end
>
> w_a_detail.rb:
>
> Class WADetail < ActiveRecord::Base
>     set_primary_key :w_a_detail_id
>     set_table_name "w_a_details"
>     attr_accessible :description,:request_id,:w_a_detail_id
>     belong_to :a_w_request, :foreign_key "request_id"

That should be belongs_to not belong_to and foreign_key: "request_id"
or :foreign_key => "request_id"

Colin