2016-06-10 46 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行動。