简体   繁体   中英

Unable to save data add to the model created with Devise (name model : user )

I use currency with ruby rails 4, I add fields in my user table I created with currency and the concern is when I want to change my email it works but if I want to update the other fields nothing happens so I do not know what 'would forget.

Here the form of currency or I add the fields.

%h2
 Edit #{resource_name.to_s.humanize}
 = form_for(resource, :as => resource_name, :url => registration_path(resource_name),  :html => { :method => :put }) do |f|
= devise_error_messages!
%div
 = f.label :email
 %br
 = f.email_field :email, :value =>"#{current_user.email}"
%div
= f.label 'Mot de passe'
%i (Pour valider votre profil)
%br
= f.password_field :current_password
%div
 = f.label 'Nom'
%br
 = f.text_field :username, :value=>"#{current_user.username}"
%div
 = f.label 'Prenom'
 %br
 = f.text_field :firstname, :value=>"#{current_user.firstname}"
%div
= f.label 'Adresse'
%br
= f.text_field :adress, :value=>"#{current_user.adress}"
%div
 = f.label 'Code postal'
%br
 = f.text_field :cp, :value=>"#{current_user.cp}"
%div
 = f.label 'Ville'
%br
 = f.text_field :city, :value=>"#{current_user.city}"
%div= f.submit "Mise à jour du profil"

To update the custom fields that you added to Devise model, you will have to permit them explicitly:

Add the following code in your ApplicationController

class ApplicationController < ActionController::Base

  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    ## Permit the custom fields below which you would like to update, I have shown a few examples 
    devise_parameter_sanitizer.for(:account_update) << :currency << :username << :firstname
  end   

end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM