Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Use of nifty:authentication before_filter problem #111

Closed
belgoros opened this issue Jun 24, 2011 · 2 comments
Closed

Use of nifty:authentication before_filter problem #111

belgoros opened this issue Jun 24, 2011 · 2 comments
Labels

Comments

@belgoros
Copy link

Hi Ryan!
I have a problem to integrate a 'before_filter' into the ApplicationController when using nifty authentication option of nifty generator. Here is what I did:

  • generated nifty layout: rails g nifty:layout : OK
  • generated nifty authentication using the command as indicated: rails g nifty:authentication OK
  • generated projects scaffold as rails g nifty:project name:string
  • rake db:migrate
  • added the below lines into the ApplicationController:
class ApplicationController < ActionController::Base
  include ControllerAuthentication
  protect_from_forgery
  before_filter :login_required, :except=> [:login_url, :signup_url, :logout_url]
end

After running 'rails s' I got:

Started GET "/login" for 127.0.0.1 at 2011-06-24 15:04:09 +0200
  Processing by SessionsController#new as HTML
Redirected to http://localhost:3000/login
Completed 302 Found in 0ms

The above message turned out in the terminal window and in the Firefox browser I got the following message:
The page could be displayed correctly
Firefox has detected that the server redirected the request for this address endlessly
The problem may be due to the cookies desactivation or its protection

What did I do wrong? Why can't I put the 'before_filter' in ApplicationController as I did before this nifty option?
I got it on Windows XP PC, Rails 3.0.9, Ruby 1.9.2.
Thanks in advance.

@ryanb
Copy link
Owner

ryanb commented Jun 29, 2011

Passing :except=> [:login_url, :signup_url, :logout_url] will not work. Those are named routes you are passing. You need to specify the name of the controller action. Instead, add a skip_before_filter option to the SessionsController.

# application_controller.rb
before_filter :login_required

# sessions_controller.rb
skip_before_filter :login_required, :only => [:new, :create]

# users_controller.rb
skip_before_filter :login_required, :only => [:new, :create]

Does that work for you?

@belgoros
Copy link
Author

Great ! Thanks a lot Ryan, it works now !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants