2012-02-22 8 views
0

OK、シナリオは次のとおりです。同じコントローラに3つのネストされたフォームを保持しようとしています。ユーザーとショップの関係が円滑に機能しているので、ショップとshop_typeの間に問題が発生します。 だから、私はショップ編集ビューでshop_type情報ActiveRecord :: AssociationTypeMismatch

は、このエラーを吐き出す更新しようとすると:ShopType(#70233617878800)予想を、activesupportのだ:: HashWithIndifferentAccess(#70233610891660)

私は検索すでにこれについてはapi docsではなく、shop_typeがハッシュとして渡している理由はまだ私の謎です。

ありがとうございました。

ShopsController

def new 
    @user = current_user 
    @shop = @user.build_shop.shop_type 

    end 


    def create 
    @user = current_user 
     @shop = @user.build_shop(params[:shop]) 
      if @shop.save 
     flash.now[:success] = "blah" 
     render :edit 
     else 
     render :new 
    end 
    end 

    def edit 
@user = current_user 
    if @shop = current_user.shop 
    render :edit 
    else render :new 
    end 
end 


    def update 
     @user = current_user 
      @shop = current_user.shop 
     if @shop.update_attributes(params[:shop]) 
     flash.now[:success] = "blah" 
     render :edit 
     else 
     render :edit 
    end 
    end 
end 

ShopModel

belongs_to :user 
belongs_to :shop_type 

Shop_typeModel

has_many :shops 
    accepts_nested_attributes_for :shops 
attr_accessible :shops, :shop_attributes 

答えて

1

、まだ私はを使用する必要がない明確な理由を与えることができないあなたのレールのクラスでクラスや変更をキャッシュすることを知っている必要があります。shop_type fields_for上:だけではなくをshop_type_id。

0

の変更行:

config.cache_classes = true 

このエラーが発生する理由はわかりませんが、この方法でこの問題が解決されます。しかし、あなたはそれが私が知るどんな効果

+0

興味深いことに、私はこれをやっていますが、実際のところ、cache_classesはtrueに設定されています。 – dcalixto

+0

私はあなたのparamsにバグがあると思います。 params [:shop]を含むものを表示できますか? '' params [:shop] .inspect' – ka8725

+0

私は人間ですが、安定したバージョンをリリースするまで、Ruby 1.9.3のデバッガは盗難されて非常に痛いです。 – dcalixto

関連する問題