如果想要在devise套件裡增加欄位該怎麼做呢?create the migrationd可以看此篇有關users的部份,以下就直接跳到create controller的步驟嘍!
首先,先新增一個RegistrationsController
$ rails g controller registrations
打開registrations_controller.rb檔,編輯內容,注意class的地方不一樣,有做繼承devise的動作
#class RegistrationsController < ApplicationController
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:cname, :phone1, :phone2, :address, :zipcode, :email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:cname, :phone1, :phone2, :address, :zipcode, :email, :password, :password_confirmation, :current_password)
end
end
修改config/routes.rb
#devise_for :users
devise_for :users, :controllers => { registrations: 'registrations' }
Done.
沒有留言:
張貼留言