Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Due to some recent changes in the `rails4` branch of Devise, I needed to update the code I borrowed from https://gist.github.com/kazpsp/3350730. Here it is. Read more on the [Rails 4 Devise branch README](https://github.com/plataformatec/devise/tree/rails4#strong-parameters). If you want to see what options you can pass into `devise_parameter_sa…
# controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
# my custom fields are :name, :heard_how
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:name, :heard_how,
:email, :password, :password_confirmation)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:name,
:email, :password, :password_confirmation, :current_password)
end
end
end
@pedroassumpcao

This comment has been minimized.

Show comment
Hide comment

Thanks!

@chubchenko

This comment has been minimized.

Show comment
Hide comment

Thanks!

@benbonnet

This comment has been minimized.

Show comment
Hide comment

great!

@pcanterini

This comment has been minimized.

Show comment
Hide comment
@pcanterini

pcanterini Aug 5, 2013

Life saver! Thank you.

Life saver! Thank you.

@Gaurav2728

This comment has been minimized.

Show comment
Hide comment
@Gaurav2728

Gaurav2728 Aug 13, 2013

Thanks ...it's really work......!!

Thanks ...it's really work......!!

@huertanix

This comment has been minimized.

Show comment
Hide comment
@guyisra

This comment has been minimized.

Show comment
Hide comment

guyisra commented Feb 5, 2014

👍

@Verkalets

This comment has been minimized.

Show comment
Hide comment

Thanks!

@melhotiby

This comment has been minimized.

Show comment
Hide comment
@melhotiby

melhotiby Jun 3, 2014

Thanks 👍

Thanks 👍

@diegobernardes

This comment has been minimized.

Show comment
Hide comment

Thanks!

@Ruby-rocker

This comment has been minimized.

Show comment
Hide comment
@Ruby-rocker

Ruby-rocker Nov 14, 2014

Try this for custom fields (:first_name, :last_name) as strong parameter

class RegistrationsController < Devise::RegistrationsController

private

def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end

def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end

Try this for custom fields (:first_name, :last_name) as strong parameter

class RegistrationsController < Devise::RegistrationsController

private

def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end

def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end

@juddey

This comment has been minimized.

Show comment
Hide comment
@juddey

juddey May 11, 2015

Thanks @Ruby-rocker, works good :)

juddey commented May 11, 2015

Thanks @Ruby-rocker, works good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment