0

我有這樣的評論型號:的Rails 3.2嵌套表單定製外鍵無法保存

class Review < ActiveRecord::Base 
    attr_accessible :approved, :reviewed_id, :for, :user_id, :text, :rating, :title 

    belongs_to :business 
    belongs_to :product 
end 

這產品型號:

class Product < ActiveRecord::Base 
    include ApplicationHelper 
    belongs_to :business 
    belongs_to :catalog 
    belongs_to :category 

    has_many :reviews, :foreign_key => :reviewed_id 
    has_many :features, :dependent => :destroy 
end 

和這種商業模式:

class Business < ActiveRecord::Base 
    validates_presence_of :name 
    validates_presence_of :category 

    mount_uploader :photo, PhotoUploader 

    has_many :catalogs, :dependent => :destroy 
    has_many :products, :dependent => :destroy 
    has_many :branches, :dependent => :destroy 
    has_many :reviews, :foreign_key => :reviewed_id 
end 

但是在評論控制器中使用此創建操作:

def create 
    @business = Business.find(params[:business_id]) 

    if params.has_key?('product_id') 
    @product = Product.find(params[:product_id]) 
    @review = @product.reviews.build(params[:review]) 

    if @review.save 
     flash[:notice] = 'Pending Review Submitted' 
     redirect_to business_product_path(@business, @product) 
    else 
     @form_resources = [@business, @product, @review] 
     respond_with(@business, @product, @review) 
    end 
    else 
    @review = @business.reviews.build(params[:review]) 

    if @review.save 
     flash[:notice] = 'Pending Review Submitted' 
     redirect_to business_path(@business) 
    else 
     @form_resources = [@business, @review] 
     respond_with(@business, @review) 
    end 
    end 
end 

我無法保存關聯。 simple_form表示存在錯誤,但我看不到日誌中的錯誤,並且所有其他字段都經過驗證,因此我猜測關聯存在問題。

面臨的問題:我該如何讓simple_form顯示所有錯誤?

回答