2012-05-27 16 views
0

我做了以下型号:的ActiveRecord :: UnknownAttributeError Rails中使用STI车型时

class Request < ActiveRecord::Base 
end 

class UrgentRequest < Request 
    has_one:note 
end 

class Note < ActiveRecord::Base 
    attr_accessible :request_id,.... 
    belongs_to :urgent_request, :foreign_key=>'request_id', :class_name=>'Request' 
end 

在我的控制,我成立了一个行动,以创建UrgentRequest对象:

def new_scheduled_request 
    @request = UrgentRequest.new 
    @request.build_note #<-- getting error here 

    respond_to do |format| 
    format.html # new.html.erb 
    format.json { render json: @request } 
    end 
end 

我会出现以下错误:

ActiveRecord::UnknownAttributeError in RequestsController#new_urgent_request 
unknown attribute: urgent_request_id 

行号是我在调用build_note电话。页面上的表单应该是嵌套表单。这里发生了什么,我该如何解决它?

回答

1

呃没关系,我发现这个问题。显然我必须在UrgentRequests模型中明确提到has_one:note关联外键和类名参数。现在正常工作!

相关问题