Thursday, 10 July 2014

ADD CUSTOM FIELDS TO DEVISE GEM

To add Custom fileds to devise gem:

$ rails generate devise:views
#to generate views

$rails generate migration AddLocationColumnToUsers location_name:string gender:string

#Add field names to users table with migration

then,

Add fields to signup form....

then add below lines to your application controller...

#strong parameters saving in database
before_filter :configure_permitted_parameters, if: :devise_controller?

 protected
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:location_name,:gender,:email, :password, :password_confirmation) }
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:location_name,:gender,:email, :password, :password_confirmation) }
  end

:-)

No comments:

Post a Comment