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
興味深いことに、私はこれをやっていますが、実際のところ、cache_classesはtrueに設定されています。 – dcalixto
私はあなたのparamsにバグがあると思います。 params [:shop]を含むものを表示できますか? '' params [:shop] .inspect' – ka8725
私は人間ですが、安定したバージョンをリリースするまで、Ruby 1.9.3のデバッガは盗難されて非常に痛いです。 – dcalixto