0
응용 프로그램이 네 페이지 (client_details, client_process, login, validate_login)를 허용하도록 조치 전에 건너 뛰기를 사용했습니다. 그러나 내가 기대했던대로 행동은 효과가 없다. 사용자가 로그인 할 수 없습니다. 나는 이유를 모른다. 친절하게 도와주세요.Rails 4에서 건너 뛰지 않는 작업 건너 뛰기
내 사용자 컨트롤러,
class UsersController < ApplicationController
skip_before_action :check_session, :only=>[:client_details,:client_process,:login,:validate_login]
require 'securerandom'
def client_details
@client=Client.new
end
def client_process
params.permit!
@client=Client.new(client_params)
if @client.save
Notify.scop(@client).deliver
flash[:notice] = " your infomation is registered,wait for approval"
redirect_to :action=> "login"
else
render "client_details"
flash[:notice] = "sorry..."
end
end
def login
@user=User.new
render :layout=>false
end
def validate_login
params.permit!
@user=User.where params[:user]
[email protected](:id)[0]
if not @user.blank?
@chk=User.where(:username=>params[:user][:username]).pluck(:role)[0]
@chk1=User.where(:username=>params[:user][:username]).pluck(:block_status)[0]
if @chk=="Admin"
if @chk1==nil
session[:user_id][email protected]
redirect_to :action=>"admin_page"
else
flash[:notice] = "sorry!... Administrator blocked you..."
redirect_to root_path
end
elsif @chk=="user"
redirect_to root_path
elsif @chk==nil
redirect_to :action=>"client_page"
end
else
flash[:notice] = "Enter valid username and password"
redirect_to root_path
end
end
end
내 응용 프로그램 컨트롤러, 당신은했다 준
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :check_session
def check_session
if session[:user_id].blank?
redirect_to root_path
end
end
end
'check_session'이 분명히 호출 되었습니까? 아니면 다른 것의 부작용 일 수 있습니까? 확실하지 않은 경우'check_session'의 시작 부분에'raise' 또는'puts'를 사용해보십시오. – tombeynon
check_session이 호출되었습니다. 내 서버 로그를보십시오. 2016-06-10의 192.168.1.102에 "/ users/client_page"GET 시작 16:48:46 +0530 192.168.1.102에서 콘솔을 렌더링 할 수 없습니다! 허용 된 네트워크 : 127.0.0.1, :: 1, 127.0.0.0/127.255.255.255 UsersController # client_page에서 HTML로 처리 http://192.168.1.59:3000/ 로 리디렉션 됨 ** 필터 체인이 check_session 렌더링 또는 방향 전환 ** 완료 됨 302 2ms에서 발견 – kelvin
아아, skip_before_action에는 #client_page – tombeynon