Skip to content

Instantly share code, notes, and snippets.

@kazpsp
Forked from guilleiguaran/passwords_controller.rb
Created August 14, 2012 16:40
Show Gist options
  • Star 56 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save kazpsp/3350730 to your computer and use it in GitHub Desktop.
Save kazpsp/3350730 to your computer and use it in GitHub Desktop.
StrongParameters with Devise
# app/controllers/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
private :resource_params
end
# app/controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
def resource_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
private :resource_params
end
# config/routes.rb
devise_for :users, :controllers => {:registrations => "users/registrations", :passwords => "users/passwords"}
@bluemont
Copy link

The rails4 branch of Devise has some recent changes that are important for this discussion. See: heartcombo/devise@3ed0dc5 Or just view the README: https://github.com/plataformatec/devise/tree/rails4#strong-parameters

I made a Gist showing the code I use: https://gist.github.com/bluemont/e304e65e7e15d77d3cb9

@istana
Copy link

istana commented May 3, 2013

thanks for the update

@pawel2105
Copy link

Thanks!

@deneuxa
Copy link

deneuxa commented May 20, 2013

Thanks ! :)

@albrow
Copy link

albrow commented May 23, 2013

Checkout @sferik's fork if you are using recoverable or want to let users change their password...
better version

You need to add a few more params to the list or else you will get errors. Saved me some trouble.

@mastfish
Copy link

mastfish commented Jun 4, 2013

I've made a gist based on the lazy suggestion for devise that handles multiple models at https://gist.github.com/mastfish/5702796 .

It saves having to create custom controllers.

@rusllonrails
Copy link

Thanks )

@abkreno
Copy link

abkreno commented Jul 30, 2015

Thanks 👍

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