2013-06-18 44 views
0

我有一個地主階級,評論類,地主有很多評論(1:N)Rails的提交包含嵌套類的表單,創建問題

我每次提交表單(form是@landlord幷包含在表單中嵌套註釋) 我在註釋db中創建3個插入,我無法識別是什麼導致此問題。我想要的是要創建的房東,然後一旦保存,評論與房東相關聯並保存到分貝。

我相當肯定的評論#create沒有被調用。

我是新來的鐵軌,並感謝幫助。 謝謝。

landlords_controller

def new 
    @landlord = Landlord.new 
    @landlord.comments.build 
end 

    def create  
    @landlord = Landlord.create(params[:landlord]) 
    if @landlord.save 
     flash[:success] = "Thank you for submitting a Landlord" 
     redirect_to landlords_path 
    else 

    end 
    end 

comments_controller

def create 
    @comment = landlord.comments.build(params[:comment]) 
    if @comment.save 
     @comment.setIP request.remote_ip 
    else 

    end 
end 

回答