Automatic login as guest

84 views
Skip to first unread message

AK

unread,
Sep 29, 2010, 3:37:57 PM9/29/10
to Devise
I want my whole application to be "secured", i.e. putting the
authenticate_user! before_filter in the ApplicationController.

But of course that means that upon visiting the site, users are
redirected to the Devise login page.

What I would like to do is automatically establish a session for a
"guest" user when a user first visits the site, if they do not already
have an authentication token.

I am confused about where to put the code to establish this default
"guest" session. Can anyone help?

I will count anyone saying my idea is terrible because x, y, and z as
help, also ;-)

AK

unread,
Sep 29, 2010, 4:58:40 PM9/29/10
to Devise
So I thought "Well, I'll do this in a before_filter in
application_controller.rb." Like this:

class ApplicationController < ActionController::Base

before_filter :auth, :except => [:auth]

layout 'application'

protected

def auth
if *user is signed in, however the HELL I do that*
user = User.find_by_name("guest")
sign_in(@user)
else
authenticate_user!
end
end

end

Simple enough, right?

Wrong. Too many redirects.

I am missing something very simple, like always.

I have been reading the Devise code for clues on how to use it. It's
very well-written of course and I can follow much of it. But when I
see stuff like:

included do
helper DeviseHelper

helpers = %w(resource scope_name resource_name
resource_class devise_mapping devise_controller?)
hide_action *helpers
helper_method *helpers

prepend_before_filter :is_devise_resource?
skip_before_filter *Devise.mappings.keys.map { |
m| :"authenticate_#{m}!" }
end

My mind immediately goes into shutdown mode. See those asterisks? I
don't even know what those mean, after 5 years of coding in Rails. I
don't know how to improve.

Back to my immediate question, I am trying to figure out how to
automatically log in an un-logged-in user as "Guest".
Reply all
Reply to author
Forward
0 new messages