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?
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:
Hope that helps!
Thanks OP for your reply. I also would like to know more how to add username instead of an email.