3

ネストされた属性を割り当てようとするとログに次のようなメッセージが表示されます。私はスキャンし、私が見つけることができるすべての答えを試みたが、何も動作しません。取得保護された属性を一意に割り当てることができません:アドレス

Started POST "/admin/care_homes" for 127.0.0.1 at 2012-02-11 23:27:24 +0100 Processing by Admin::CareHomesController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zymx7VQU1mi+ho5T+Ups6cvHavpE4ClU6g1QFi+Y3z8=", "care_home"=>{"organisation_name"=>"", "cqc_id"=>"", "csa_id"=>"", "address"=>{"street_address"=>"", "address_line_two"=>"", "city"=>"", "county_id"=>"1", "postcode"=>""}, "registered_manager"=>"", "telephone_number"=>"", "website"=>"", "region_id"=>"1", "authority_id"=>"1", "provider_id"=>"11789", "details"=>"", "directions"=>""}} User Load (0.4ms) SELECT users .* FROM users WHERE users . id = 4 LIMIT 1

WARNING: Can't mass-assign protected attributes: address

私はCareHome <のSTIを持っています。アドレスは多相関係です。

私が持っているサービスで

class Service < ActiveRecord::Base 

    paginates_per 15 

    image_accessor :home_image 

    has_one :address, :as => :addressable, :validate => true 
    has_one :county, :through => :address 

    attr_accessible :organisation_name, :cqc_id, :csa_id, :registered_manager, 
       :telephone_number, 
       :website, :region_id, :authority_id, :provider_id, 
       :details, :directions, :home_image, :retained_home_image, 
       :county, :address_attributes 

    accepts_nested_attributes_for :address 

CareHomeController#では私が追加した場合は、新規作成/私は

def new 
    @care_home = CareHome.new 
    @care_home.build_address 
end 

def create 
    @care_home = CareHome.new(params[:care_home]) 
    if @care_home.save 
    redirect_to admin_care_home_path(@care_home), :notice => 'Saved' 
    else 
    render 'new' 
    end 
end 


class Address < ActiveRecord::Base 

    attr_accessible :id, :street_address, :address_line_two, :city, :county_id, :postcode, :country_id, :addressable_id, :addressable_type 

    belongs_to :addressable, :polymorphic => true 
    belongs_to :county 

を持っている:私はエラーを取得するattr_accessibleにアドレス:

Address(#2560574700) expected, got ActiveSupport::HashWithIndifferentAccess(#2157282280)

私のRailsのバージョンは3.1.1です。

私はそれが何か微妙なものでなければならないと思うが、私は試しにアイデアが不足している。どんな助けもありがとう!

答えて

0

attr_accesssibleを書く理由はありますか?

この行をコメントアウトして試してください。

+0

ドキュメントに記載されているので。私はそれを取り除こうとしたが、私は同じエラーが発生します。 – Geoff

+0

あなたの新しいフォームを見せてください – DeathHammer

+0

私はそれを見つけたと思います。 、部分的=> "の形式を":地元の人々{:=> F fはフィールド名 'アドレス' でフォームを作成します 私は を使用する場合は、 ' "フォーム" をレンダリングし、:=> F fをレンダリング' を使用して 次に、フィールド名が「address_attributes」のフォームを作成してもOKです。 なぜ違いがあるのか​​分かりませんか? – Geoff

関連する問題