# Exception class location in the rails framework

**URL:** <https://www.ruby-forum.com/t/exception-class-location-in-the-rails-framework/116549>\
**Category:** Rails\
**Created:** [October 7, 2007, 6:12am UTC](https://www.ruby-forum.com/t/exception-class-location-in-the-rails-framework/116549 "2007-10-07T06:12:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [October 7, 2007, 6:12am UTC](https://www.ruby-forum.com/t/exception-class-location-in-the-rails-framework/116549/1 "2007-10-07T06:12:31Z")

</div>

Hi all,  
I have a basic noobie question, but I can’t find my answer. I’ve  
installed the acts as authenticated plug-in, and its incredibly easy  
to use. My only issue is that it doesn’t give explicit exceptions for  
different conditions of a login failure. For instance, if a login id  
doesn’t exist, I’d like to raise the “NoSuchUser” exception, if they  
haven’t confirmed registration, I’d like to raise the  
“UserNotActivated” exception. These error are raised in the user  
model, and I’d like to catch them in the controller and flash the  
appropriate message. Where in the rails framework layout would I  
define the exception classes? I’d like to keep a class file per ruby  
file for cleaner code, and it doesn’t seem that they belong in the  
“app” directory.

Thanks  
Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [October 7, 2007, 6:21am UTC](https://www.ruby-forum.com/t/exception-class-location-in-the-rails-framework/116549/2 "2007-10-07T06:21:52Z")

</div>

Hi Todd

I think you cn find your answer by looking at this modified version of  
AAA login method

def login  
return unless request.post?  
self.current\_user = User.authenticate(params[:login],  
params[:password])  
if logged\_in?  
if params[:remember\_me] == “1”  
self.current\_user.remember\_me  
cookies[:auth\_token] = { :value =\>  
self.current\_user.remember\_token , :expires =\>  
self.current\_user.remember\_token\_expires\_at }  
end  
# redirect\_back\_or\_default(:controller =\> ‘/account’, :action  
=\> ‘index’)  
# redirect\_back\_or\_default(:controller =\> ‘main’ , :action  
=\> ‘index’)  
redirect\_back\_or\_default(:controller =\>  
‘messages\_inbox’ , :action =\> ‘list’)

```
  flash[:notice] = "Logged in successfully"

else
  flash[:notice] = "Invalid Login/Password !"

end

```

end

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [October 7, 2007, 6:28am UTC](https://www.ruby-forum.com/t/exception-class-location-in-the-rails-framework/116549/3 "2007-10-07T06:28:53Z")

</div>

Hi Todd

I think you cn find your answer by looking at this modified version  
of  
AAA login method

def login  
return unless request.post?  
self.current\_user = User.authenticate(params[:login],  
params[:password])  
if logged\_in?  
if params[:remember\_me] == “1”  
self.current\_user.remember\_me  
cookies[:auth\_token] = { :value =\>  
self.current\_user.remember\_token , :expires =\>  
self.current\_user.remember\_token\_expires\_at }  
end  
# redirect\_back\_or\_default(:controller =\> ‘/  
account’, :action  
=\> ‘index’)  
# redirect\_back\_or\_default(:controller =\> ‘main’ , :action  
=\> ‘index’)  
redirect\_back\_or\_default(:controller =\>  
‘messages\_inbox’ , :action =\> ‘list’)

```
  flash[:notice] = "Logged in successfully"

else
  flash[:notice] = "Invalid Login/Password !"

end

```

end

CCH

> **[Rails... Rails... Rails](http://cch4rails.blogspot.com)**
>
> Chee Chong Hwa aka CCH, a Malaysian Chief Software Architect blogs on his experiences with Ruby on Rail running on Win2003 Server+Apache 2.26 environment since 2007. Flirted briefly with Ubuntu 9.04 in 2009. Since January 2017, now using RubyMine...
