第一步,重写 users_controller.rb
class Clearance::UsersController < ApplicationController skip_before_filter :authorize, only: [:create, :new] before_filter :avoid_sign_in, only: [:create, :new], if: :signed_in? def new @user = user_from_params render template: 'users/new' end def create @user = user_from_params if @user.save sign_in @user redirect_back_or url_after_create else render template: 'users/new' end end def edit @user = current_user render template: 'users/edit' end def update @user = current_user @user.password = params[:user][:password] @user.weixin_sk = params[:user][:weixin_sk] @user.weixin_ak = params[:user][:weixin_ak] if @user.save redirect_back_or url_after_create else render template: 'users/edit' end end private def avoid_sign_in redirect_to Clearance.configuration.redirect_url end def url_after_create Clearance.configuration.redirect_url end def user_from_params user_params = params[:user] || Hash.new email = user_params.delete(:email) password = user_params.delete(:password) weixin_ak = user_params.delete(:weixin_ak) weixin_sk = user_params.delete(:weixin_sk) Clearance.configuration.user_model.new(user_params).tap do |user| user.email = email user.password = password user.weixin_ak = weixin_ak user.weixin_sk = weixin_sk end end # def permit_params # params.require(:user).permit(:weixin_ak,:weixin_sk, :email, :password) # endend
第二部 增加路由
resources :users,controller: 'clearance/users',only: [:edit,:update]