0
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!, :except => [:index]
before_action :authenticate, :except => [:index]
def authenticate
authenticate_or_request_with_http_basic do |username, password|
basic_auth=User.find_by_email(username)
if basic_auth.valid_password?(password)
sign_in :user, basic_auth
render :json => {:email => current_user.email, :id => current_user.id, :message => "hai ruby"}
else
render plain: "Unauthorized access"
end
end
end
end
샘플 애플리케이션에서 기본 인증을 구현하려고합니다. 사용자 데이터베이스에서 올바른 자격 증명 값을 제공합니다. 그것은 사용자 이름과 암호가 잘못되면 json 응답을 제공합니다. "정의되지 않은 메소드`valid_password? '와 같은 오류가 발생합니다. 전무을 위해 : NilClass "레일의 기본 인증
정말 고마워요. – rthi