Exception class location in the rails framework

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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs