config/routes.rb
:
Rails.application.routes.draw do
namespace :user do
get :sign_in, to: 'session#new'
post :sign_in, to: 'session#create'
delete :sign_out, to: 'session#destroy'
end
root 'user/session#show'
end
$ rails generate controller user/session show new
Gemfile
:
gem 'bcrypt'
$ rails generate scaffold user state name description email username password_digest roles:text
$ rake db:migrate
$ rails generate bootswatch:themed Users --force
app/models/user.rb
:
class User < ActiveRecord::Base
has_secure_password
serialize :roles, Array
class << self
def sign_in(params)
find_by(username: params[:username]).try(:authenticate, params[:password])
end
end
end
db/seeds.rb
:
User.create_with(name: :ruby, password: :pass).find_or_create_by(username: :user)
$ rake db:seed
app/controllers/application_controller.rb
:
app/controllers/user/session_controller.rb
:
app/views/user/session/new.html.erb
:
app/views/user/session/show.html.erb
:
gem 'font-awesome-rails'
gem 'gravatar_image_tag'
app/views/layouts/_navbar.html.erb
: