ネストされたパラメータでこの奇妙な動作が発生しています。 私はそれが私が唯一のモデルを持っている私の組織タイプの場合Unpermitted parameter: organization_type
ネストされたパラメータで奇妙な動作が発生する
を言いますが、私は属性が私の理解
ごとに、ユーザーのコントローラで処理されているので、それは問題であるべきとは思わないフォームを保存しようとすると、フォームとコントローラホワイトリストの両方でorganization_type(単数)として属性を使用しようとしましたが、動作しません。
しかし、私が:organization_types
を持っていれば、フィールドは表示されません。
私は本当にこれに困惑しています。
そう簡単にまとめとして::organization_type
:
- 私は私が持っている形でOrganizationType
- 用のコントローラを持っていません。私が持っているユーザーモデルでは
:organization_types_attributes
- ::私は複数形ならば、それは私が持っているコントローラーホワイトリストに
- を示していないHAS_MANYと
:organization_types_attributes
ユーザーモデル
class User < ActiveRecord::Base
has_many :events
has_many :organization_types
accepts_nested_attributes_for :organization_types
end
組織のためaccepts_nestedタイプモデル
class OrganizationType < ActiveRecord::Base
belongs_to :user
ORG_TYPES = ['health', 'non-profit', 'foo', 'bar']
end
ユーザーCo ntroller
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!
...
def user_params
params.require(:user).permit(:name, ..., organization_types_attributes: [:id, :user_id, :org_type, '_destroy'])
end
ユーザーフォーム
<%= form_for(@user) do |f| %>
...
<div class="field">
<%= f.label :organization_type %><br>
<%= f.fields_for :organization_type do |builder| %>
<%= builder.select :org_type, options_for_select(OrganizationType::ORG_TYPES) %><br/>
<% end %>
</div>
<% end %>
私は...にhas_oneと@Renが言及した文書に従うことを、私のモデルを変更し、今それは働いているようだ。私が気づく2つの事柄です。 1.私の選択ヘルパーが最後に保存されたものを表示していません。私はこのレコードを更新するのではなく、この<%= builder.select:org_type、options_for_select(OrganizationType :: ORG_TYPES、:selected => @ user.organization_type.org_type)%> ' - 2を試しました。 – Marrento