Ich erlebe dieses seltsame Verhalten mit verschachtelten Parametern. Wenn ich versuche, das Formular zu speichern es sagt Unpermitted parameter: organization_type
Seltsames Verhalten mit verschachtelten Parametern
Für meine Art der Organisation nur ich ein Modell habe, aber ich glaube nicht, dass das Problem sein soll, weil die Attribute in dem Benutzer Controller pro meinem Verständnis behandelt werden
Ich habe versucht, die Attribute als organisation_type (singular) in Form und Controller Whitelist, aber das funktioniert nicht. In der Form, wenn ich :organization_types
habe, wird das Feld nicht angezeigt.
Ich bin wirklich verwirrt.
Um eine schnelle Rekapitulation:
- ich für OrganizationType
- In der Form habe ich nicht einen Controller haben:
:organization_type
. Wenn ich es pluralize zeigt nicht - In der Controller-weiße Liste Ich habe:
:organization_types_attributes
- Im User-Modell habe ich: has_many und accepts_nested für
:organization_types_attributes
Benutzermodell
class User < ActiveRecord::Base
has_many :events
has_many :organization_types
accepts_nested_attributes_for :organization_types
end
Organisation Typen
class OrganizationType < ActiveRecord::Base
belongs_to :user
ORG_TYPES = ['health', 'non-profit', 'foo', 'bar']
end
Benutzer 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
User Form
<%= 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 %>
ich meine Modelle geändert ... has_one und der Dokumentation @Ren erwähnt folgen und jetzt scheint es zu funktionieren. Die 2 Dinge, die ich bemerke, sind. 1. Mein ausgewählter Helfer zeigt nicht den zuletzt gespeicherten an. Ich probierte dieses '<% = builder.select: org_type, options_for_select (OrganizationType :: ORG_TYPES,: ausgewählt => @ user.organization_type.org_type)%>' - 2. anstatt den Datensatz zu aktualisieren, erstellt er einen neuen – Marrento