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

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.


class AWRequest <ActiveRecord::Base
    set_primary_key : request_id
    set_table_name: w_r_details
    attr_accessible : request_id,

    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? } }


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"

I do not have an attribute a_w_request_id in my table which acts as
foreign key instead i have request_id as foreign key in w_a_details
table which references request_id primary key in w_r_details table that
uses a_w_request model(specified using set_table_name property). Am
using oracle as my backend.

I get the error in the following line in my controller

Below is my controller's new and create methods:

def new
respond_to do |format|
    format.json {render json:@a_w_request}

def create[:a_w_request])
respond to do |format|
        format.html{redirect_to @a_w_request,notice:'request successfuly
        format.json{render json: @a_w_request, status :created, location
        format.html {render action: "new"}
        format.json { render json :@a_w_request.errors, status:
:unprocessable entity}

Here is my form: /a_w_request/_form.html.erb:

<%=nested_form_for(@a_w_request) do |f| %>
<%= f.text_field :requester_contact %>
<%= f.date_select :needed_by %>
<%= render :partial=>'w_a_details/form',:locals=>{:form=>f} %>
<%= f.link_to_add "add request", :w_a_details %>
<%= f.submit %>
<% end %>


<%=form.fields_for :w_a_details do |a| %>
<%=a.text_field :description %>
<%=a.link_to_remove "remove" %>
<% end %>

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


Hi Colin
Sorry for the typo error. My code has belongs_to and
:foreign_key=>"request_id" . Still it throws this error. Looks like I
have to use alias_attribute functionality to map
asin_whitelist_request_id to request_id in my table. But am not sure
about how to handle the queries.