Authentication Rails
Scaffold User
rails g scaffold nome email password_digest
Gemfile
gem 'bcrypt-ruby', '~> 3.0.0'
user.rb
• Remover a validação de presença de senha
• Remover a validação de confirmação de senha
• Adicionar a class macro has_secure_password
has_secure_password
_form.html.erb
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
user_session.rb
class UserSession
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
extend ActiveModel::Translation
attr_accessor :email, :password
validates_presence_of :email, :password
end
routes.rb
resource :user_sessions, :only => [:create, :new, :destroy]
user_sessions_controller.rb
class UserSessionsController < ApplicationController
def new
@session = UserSession.new
end
def create
end
def destroy
end
end
Nenhum comentário:
Postar um comentário