Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page isn't redirecting properly Ruby on Rails

For some reason, I am getting an error when clicking on a protected part of my page:

Firefox: The page isn't redirecting properly

Here is the method I use in my ApplicationController:

protected
  def authorize
    unless User.find_by_id(session[:remember_token])
      flash[:notice] = "Please Log in"
      redirect_to :controller => 'sessions', :action => 'new'
    end
  end

For some reason, I am not getting access to sessions/new, which is my login page. Any help would be very much appreciated. I checked routes and I have get sessions/new.

like image 378
TopChef Avatar asked Oct 29 '25 04:10

TopChef


1 Answers

As a well educated guess, I'd say you have this:

before_filter :authorize

Which will keep redirecting to itself.

You can fix this either by passing only the ones you want:

before_filter :authorize, :only => [:action_a, :action_b]

Or specify the ones you don't want (probably preferable if you only want to stop your sessions#new action

before_filter :authorize, :except => [:new, :create]

If your before_filter is specified on an inherited controller (e.g. your SessionsController is inheriting the before_filter from ApplicationController) then you can use skip_before_filter

skip_before_filter :authorize, :only => [:new, :create]
like image 166
Gazler Avatar answered Oct 30 '25 21:10

Gazler