2015年3月19日 星期四

Adding Custom Fields to Devise User Model in Rails 4

http://www.jacopretorius.net/2014/03/adding-custom-fields-to-your-devise-user-model-in-rails-4.html

 create the migration
class AddFieldsToUsers < ActiveRecord::Migration
  def change
    add_column :users:first_name:string
    add_column :users:last_name:string
  end
end

Customizing the RegistrationsController


creating our own registrations controller (which extends Devise) and then customizing these methods as we choose.

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

Now we need to tell Devise to use our registrations controller - we can do this in ourconfig/routes.rb file.
devise_for :users:controllers => { registrations: 'registrations' }

沒有留言:

張貼留言