Rails と Ruby は初めてです。私の見解では、その人が米国の居住者かどうかを尋ねる 2 つのラジオ ボタンがあります。そうであれば、状態選択が表示されます。そうでない場合は、国の選択が表示されます。
その人が米国の居住者である場合、州が選択されたことを検証しようとしています。
検証を作成し、addresses_attributes から状態にアクセスするにはどうすればよいですか?
これが私のモデルです:
class Person < ActiveRecord::Base
has_many :addresses, :as => :addressable
has_one :user
accepts_nested_attributes_for :user, :allow_destroy => true
accepts_nested_attributes_for :addresses
attr_accessor :resident
attr_accessible :campaign_id,
:first_name,
:last_name,
:user_attributes,
:addresses_attributes,
:resident
validates :first_name, :presence => true
validates :last_name, :presence => true
validates_presence_of :resident, :message => "must be selected"
end
送信される関連パラメータは次のとおりです。
"resident"=>"true",
"addresses_attributes"=>{"0"=>{"country_code"=>"",
"state"=>""}}