2016-06-10 59 views
0

我在动作之前使用了跳过,以便应用程序应该允许四个页面(client_details,client_process,login,validate_login)。但是这个行动并没有像我预期的那样有效。它不允许用户登录。我不知道为什么。请帮忙。在动作不跳过Rails 4之前跳过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 
+1

'check_session'肯定被调用,或者这可能是别的副作用吗?如果您不确定,请在'check_session'的开头尝试使用'raise'或'puts'。 – tombeynon

+0

调用check_session。看看我的服务器日志。在2016-06-10 16:48:46 +0530 开始GET“/ users/client_page”为192.168.1.102无法从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

+0

Ahah,您的skip_before_action不包含#client_page – tombeynon

回答

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行动。