nobilik
nobilik

Reputation: 736

Devise update additional attributes without password confirmation.

Use Rails 4, Devise, Simple form. Read a lot about this, but for sure have no enough experience. I've made RegistrationController, custom views also exists. With this I have no problem with password confirmation, but all my params are unpermitted:

def update_resource(resource, params)
    resource.update_without_password(params)
end

As I understand this should be decision, but have no any effect for me:

def configure_account_update_params
    devise_parameter_sanitizer.for(:account_update) do |u|
      u.permit(:username, :first_name, :last_name, :price_plan_id, :email_notify, :msg_notify,
               :email, :password, :password_confirmation, :current_password)
    end
  end

Maybe somebody can write whole conceptual answer about it?

Upvotes: 2

Views: 138

Answers (2)

dileep nandanam
dileep nandanam

Reputation: 2885

Enable the callback for those who missed.

class ApplicationController < ActionController::Base
  before_action :configure_account_update_params, if: :devise_controller?

Upvotes: 1

Mr.D
Mr.D

Reputation: 7863

In my model which Devise is assigned I have added these methods:

def skip_devise
  @skip = true
end

def password_required?
  [email protected]? ? false : super
end

def email_required?
  [email protected]? ? false : true
end

Your model will override password_required? and email_required? methods of Devise.

When I want my model to skip these validations I just run this:

my_model.skip_devise
my_model.save!

Upvotes: 0

Related Questions