Ich verwende Devise in meiner Ruby on Rails-Anwendung. Wenn Benutzer sich anmelden oder ihr Konto aktualisieren, möchte ich auch ihre AddressInformation
erstellen/aktualisieren.Rails 5, verschachtelte Attribute, unerlaubte Parameter
class User < ApplicationRecord belongs_to :address_information accepts_nested_attributes_for :address_information, allow_destroy: true [...]
Mein _form.html.haml
sieht wie folgt aus:
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
.form-group
= f.label :name
= f.text_field :name
= f.fields_for :address_informations, resource.address_information do |address_field|
.form-group
= address_field.label :address
= address_field.text_field :address
.form-group
= address_field.label :care_of
= address_field.text_field :care_of
.form-group
= address_field.label :zip_code
= address_field.text_field :zip_code
.form-group
= address_field.label :city
= address_field.text_field :city
Ich habe versucht, die Attribute wie folgt hinzuzufügen:
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update]
[...]
# If you have extra params to permit, append them to the sanitizer.
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [
:name,
address_information: [
:address,
:care_of,
:zip_code,
:country,
:state
]
])
end
Wenn ich versuche, den Benutzer ich folgendes erhalten zu aktualisieren Fehler:
Unpermitted parameter: :address_informations
(0.2ms) BEGIN
(0.2ms) ROLLBACK
Irgendwelche Ideen, was ich vermisse?
Vielleicht nur ein Tippfehler? Der nicht erlaubte Parameter ist ': address_informations', aber Sie erlauben': address_information' in 'configure_account_update_params'. –
@DerekHopper Ich habe versucht, 'address_informations:' auch zu verwenden, aber es gibt das gleiche Ergebnis. – Anders