Telling Devise to redirect, if Username already exists, Ruby on Rails, gem Devise -


i'm using ruby on rails 4 , gem devise. added username users, following guide: https://github.com/plataformatec/devise/wiki/how-to:-allow-users-to-sign-in-using-their-username-or-email-address . username unique. whenever new user signs , wants use username, exists, gets active-record-error. works, should.

now problem: want, if user chooses existing username, should redirected registrations/new.html.erb page flash message, rather seeing activerecord-error-page. how accomplish this?

edit: code to: users::registrationscontroller#create

      class users::registrationscontroller < devise::registrationscontroller # before_filter :configure_sign_up_params, only: [:create] # before_filter :configure_account_update_params, only: [:update]    # post /resource    def create      @username = params[:username]      @usernames = user.all      @usernames.each |f|        if f.username == @username          redirect_to root_path        end      end      super    end end 

i found solution problem:

i added controller:

  # post /resource    def create      @username = sign_up_params[:username]      if usernameexists(@username)      redirect_to root_path      else       super      end    end 

and seems work way.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -