Rails 5アプリで入れ子にしたフォーム用の繭の宝石を設定しようとしています。Rails、Cocoon Gem - NilClass用の未定義メソッド `reflect_on_association ':クラス
私は、他の人が投稿したという問題がありますが、彼らのために働く解決策は私のために働いていないようです。
住所、組織、設定のモデルがあります。団体は以下のとおりです。
住所
belongs_to :addressable, :polymorphic => true, optional: true
組織
has_many :addresses, as: :addressable
accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true
設定
has_many :addresses, as: :addressable
accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true
マイ設定コントローラがあります。
def setting_params
params.require(:setting).permit(:newsletter,
addresses_attributes: [:id, :description, :unit, :building, :street_number, :street, :city, :region, :zip, :country, :time_zone, :latitude, :longitude, :_destroy]
)
end
を
私のルートは以下のとおりです。
resources :organisations do
namespace :contacts do
resources :addresses
resources :phones
end
end
resources :users, shallow: true do
scope module: :users do
resources :assign_roles
resources :identities
resources :org_requests
resources :profiles
resources :settings do
namespace :contacts do
resources :addresses
resources :phones
end
end
end
マイアドレスフォームがあります
マイ設定フォームがあります
<%= simple_form_for [@user, @setting] do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :newsletter, as: :radio_buttons, label: "Subscribe to our newsletter" %>
<%= simple_fields_for :addresses do |f| %>
<%= f.error_notification %>
<%= render 'contacts/addresses/address_fields', f: f %>
<%= link_to_add_association 'Manage address', f, :addresses, partial: 'contacts/addresses/address_fields' %>
<% end %>
</div>
<% end %>
エラーは言う:
undefined method `reflect_on_association' for NilClass:Class
この行が強調表示されていますエラーメッセージ:
<%= link_to_add_association 'Manage address', f, :addresses, partial: 'contacts/addresses/address_fields' %>
他の点では、問題は複数形の代わりに単数形を使用していました。または@addressesの代わりに使用して:アドレス(解決策のいくつかは、その代わりに、@のはずが示唆されているものの:。
私はそれぞれの組み合わせでこれらのそれぞれを試してみました
誰もが私が必要なものを見ることができます。これを設定するのですか?
私は属性がフォームに異なる方法で処理する必要があるネストされたシンプルな形式のドキュメントから参照することができ
。
EDMUNDの提案を取りますいずれかの作業をdoesntの<%= simple_fields_for "addresses_attributes[]", address do |f| %>
:
https://github.com/plataformatec/simple_form/wiki/Nested-Models#example-for-strong-parameters
210は私がにフォームを変更してみました。私は検査するページをレンダリングできません。
この文脈のエラーラインは、組織コントローラの新しいアクションに関する問題を指しています。それが持っている:
def new
@organisation = Organisation.new
@organisation.addresses_build
end
エラーメッセージは言う:
undefined method `addresses_build' for #<Organisation:0x007fcf6ff25f08>
Did you mean? addresses
私が代わりにアドレスのaddress_attributesを構築する必要がある場合、私は今のだろうか。しかし、私が試してみると、エラーが表示されます:
undefined method `addresses_attributes_build' for #<Organisation:0x007fcf72c26d68>
Did you mean? addresses_attributes=
あなたのモデルは 'Setting'か' Settings'ですか? – SteveTurczyn
setting.rb ................ – Mel