ruby on rails 4 - Devise change email does not update email -


i'm trying allow users change email addresses devise uses unique username. though update gives no errors, no change made email address user in database.

here relevant portions of code:

form:

<%= f.fields_for :user_account, @user.user_account |user_account| %>  <p>edit email address account: <%=  @user.user_account.email %></p>  <div class="field">   <%= user_account.label :new_email %><br />   <%= user_account.text_field :email, autocomplete: "off", value: nil %> </div> <div class="field">   <%= user_account.label :password %> <i>(please confirm password associated account)</i><br />   <%= user_account.password_field :current_password, autocomplete: "off" %> </div> <%= hidden_field_tag 'form', 'email' %> <div class="actions">   <%= user_account.submit "edit" %> </div> 

controller:

def update respond_to |format| if params[:form] == 'email'     if @user.user_account.valid_password?(params[:user][:user_account_attributes][:current_password])       if @user.update(user_params)         format.html { redirect_to user_path(@user), :notice => 'your new email has been saved' }         format.json { render :show, status: :ok, location: @user }       else         format.html { render :edit }         format.json { render json: @user.errors, status: :unprocessable_entity }       end     else        format.html { redirect_to edit_email_path(@user), :notice => 'incorrect password (email)' }     end  else ... 

the user_params method:

def user_params params.require(:user).permit(   :first_name, :middle_initial, :last_name,    :linkedin, :website, :facebook, :video, :phone_number,    :address_1, :address_2, :city, :zip_code,    :image, :number, :years_practicing, :neighborhood, :biography, :price, :status,   user_employments_attributes: [:id, :user_id, :company, :position, :start_date, :end_date, :info, :_destroy],    user_educations_attributes: [:id, :user_id, :school, :degree_title, :start_date, :end_date, :info, :_destroy],    user_account_attributes: [:id, :user_id, :email, :password, :password_confirmation, :_destroy],    user_category_ids:[]) end 

user account model:

 class useraccount < activerecord::base   # include default devise modules. others available are:   # , :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable, :confirmable,      :recoverable, :rememberable, :trackable, :validatable    belongs_to :user  end 

ok, turns out new email address being saved :unconfirmed_email, did not change of functionality of linked account, since account still had old email stored :email.

thus had

user.confirmed_at = nil user.save(:validate => false) 

in order user confirmation email resent , login form no longer accept old password.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -