# Perform a check and then call super class when user creates new session

**URL:** <https://www.ruby-forum.com/t/perform-a-check-and-then-call-super-class-when-user-creates-new-session/206206>\
**Category:** Rails\
**Created:** [April 25, 2011, 7:57pm UTC](https://www.ruby-forum.com/t/perform-a-check-and-then-call-super-class-when-user-creates-new-session/206206 "2011-04-25T19:57:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 25, 2011, 7:57pm UTC](https://www.ruby-forum.com/t/perform-a-check-and-then-call-super-class-when-user-creates-new-session/206206/1 "2011-04-25T19:57:07Z")

</div>

Hey all,

I’m using devise plugin for rails. When the user creates a new session,  
in addition to devise authenticating the user, I want to check if the  
user is enabled by checking the value of the enabled (a boolean) field  
in the database. If the value is 0, I want to alert user that they  
haven’t been enabled, otherwise devise can do it’s thing.

I have this:

```
class SessionsController < Devise::RegistrationsController

```

def new  
super  
end

def create  
@user = User.authenticate(params[:user][:email])  
if !@user.enabled  
raise “You are not enabled”  
else  
super  
end  
end

def update  
super  
end  
end

I have this in User model:

class User \< ActiveRecord::Base  
devise :invitable, :database\_authenticatable, :registerable,  
:recoverable, :rememberable, :trackable, :validatable

def self.authenticate(email)  
u = find(:first, :conditions=\>[“email = ?”, email])  
return nil if u.nil?  
return u  
end

scope :enabled, :conditions =\> {:enabled =\> true}

And the routes:

devise\_for :users, :controllers =\> {  
:registrations =\> “registrations”,  
:sessions =\> “sessions” }

Unfortunately right now I get a nil object error for instance variable  
@user, presumably because the params hash is not structured correctly. I  
look at html form and notice the name attribute for email says  
users[email] which is an array. So that’s why I try to do it:  
[:user][:email] but it doesn’t work. Or if you know a better way of  
doing all this, I’d greatly appreciate the knowledge.

Thanks for response.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [April 25, 2011, 10:51pm UTC](https://www.ruby-forum.com/t/perform-a-check-and-then-call-super-class-when-user-creates-new-session/206206/2 "2011-04-25T22:51:38Z")

</div>

While I almost got the behavior I want, there’s a problem:

```
def create

```

@user = User.authenticate(params[:user])  
if !@user.enabled  
render “shared\_navigation/confirmation”  
elsif request.post? #just using else instead of elsif request.post?  
gives same unwanted behavior  
super  
end  
end

When I click the create button and if the user is enabled, it reloads  
the same page and I have to click create button twice. This occurs when  
that super keyword is called which calls the super class. Anyone know  
why devise reload the same page?

Thanks for response.
