How do i use a username instead of an email?
I am watching the series and really enjoying it. I am up to Part 11 where you create the user model. Is there a way to use a username instead of email?
Hey Ookma-Kyi
Yes you can, you just need to add a user name column to your users model with a migration:
add_column :users, :user_name, :string
In your user model make sure you add a validation so it is present and unique:
validates :user_name, presence: true, uniqueness: true
In your signup form make sure you add a user_name field:
<%= f.text_field :user_name %>
And then when the user signs in, in your create session controller action search for the user by user_name rather than email:
User.find_by(user_name: params[:user][:user_name])
Hope that helps!
Thanks OP for your reply. I also would like to know more how to add username instead of an email.