mercredi 2 novembre 2016

Redirect routing wrong on :index action of controller

I am trying to apply a username validation on admin_projects_path by applying that application_controller filter into my controller which is extending the main class. When I redirect the page to root_path or any other routes things are going well. If I apply the filter only on :show action, that's going well as well. Why is the page rerouting me to the login again if I apply the filter on the :index action?

application_controller.rb

class ApplicationController < ActionController::Base

# Return the admin user
  def adminLogin
    email = params[:email]
    password = params[:password]
    if email == "username"
      redirect_to admin_projects_path
    else
      redirect_to admin_login_path unless request.fullpath == '/admin/login'
    end
  end
 end

projects_controller.rb

 class Admin::ProjectsController < ApplicationController
 before_filter :adminLogin

 # GET /admin/projects
 def index
   @projects = Project.all

   respond_to do |format|
     format.html # index.html.erb
   end
  end

 # GET /admin/projects/1
 # GET /admin/projects/1.json
 def show
   @project = Project.find(params[:id])

   respond_to do |format|
     format.html # show.html.erb
     format.json { render json: @project }
  end
 end

routes.rb

   match '/admin/login' => 'application#adminLogin'


   #Projects routes automatically generated - run 'rake routes' for more       
   info
   namespace :admin do
        resources :projects
   end

Aucun commentaire:

Enregistrer un commentaire