我在操作之前使用了skip,因此应用程序应该允许四个页面(client_details,client_process,login,validate_login)。但是这个动作并没有像我预期的那样奏效。它不允许用户登录。我不知道为什么。请帮忙。
我的用户控制器,
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]
$userid=@user.pluck(: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]=@user.first.id
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
答案 0 :(得分:0)
您提供的日志条目是..
UsersController处理#client_page为HTML重定向到192.168.1.59:3000过滤链停止为:check_session呈现或重定向完成302发现在2ms
您的UsersController中调用的操作是#client_page
。
您的skip_before_filter
不包含#client_page
skip_before_action :check_session, :only=>[:client_details,:client_process,:login,:validate_login]
因此,始终会为#check_session
操作调用#client_page
。