Distinguish between invalid username and taken username (fixes #199)

This commit is contained in:
Marcin Kulik 2015-11-02 07:52:59 +00:00
parent a32d725284
commit 94ff74d09f
2 changed files with 6 additions and 2 deletions

View File

@ -12,7 +12,7 @@ class UsernamesController < ApplicationController
if @user.update(username: params[:user][:username].strip)
redirect_to_profile(@user)
else
@invalid_username = true
@error = @user.errors[:username].to_s =~ /taken/ ? :username_taken : :username_invalid
render :new
end
end

View File

@ -16,12 +16,16 @@
.form-group
= f.label :username, 'Your username:'
= f.text_field :username, class: 'form-control', 'data-behavior' => 'focus'
- if @invalid_username
- if @error == :username_invalid
br
p.text-danger
' Use only letters, digits and "-" character.
' Examples:
em johnny-knoxville, destroyer666
- if @error == :username_taken
br
p.text-danger
' This username was already taken.
.form-group
= f.submit 'Continue', class: 'btn btn-primary'
a.btn href=skip_username_path I'll do it later