Hello, I am a Rails newbie and have a two-fold question. I recently started working with authentication. The basic authentication system is working for me, but I would like to catch errors and exceptions and display appropriate messages to the user. The first problem is that when I try to display an error message using flash[:error]="error message", it doesn''t get displayed. flash[:notice] works all right. Here is the code snippet from the controller for users where I observe the difference in behaviors. def create cookies.delete :auth_token @user = User.new(params[:user]) @user.save! self.current_user = @user redirect_back_or_default(''/contigs'') flash[:notice] = "Thanks for signing up!" rescue Activerecord::RecordInvalid redirect_back_or_default(''/login'') puts invalid.record.errors flash[:error] = "There was a problem creating your account." end The user signup page uses the "create" action of the user controller. When signup is successful, I get redirected appropriately and the notice is displayed. However, when signup is unsuccessful, the browser just displays an error page entitled " NameError in UsersController#create". Why does this happen? Second, on the error page I see the session dump as follows: :csrf_id: 1023bda9eefd568ab601761908724432 flash: !map:ActionController::Flash::FlashHash :error: Passwords do not match. Please try again! :return_to: So, it seems that the actual error that occurs gets stored in FlashHash in some way. Can I manually retrieve it and flash it on the screen? Thanks a lot for your help, Amrita --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I added <%= flash[:error] %> to the layout within an if loop. Now for the login page, if the authentication fails, it displays an error message and redirects back to itself. But for the signup page, I still don''t get redirected to ''/login'' (Now I have replaced this with ''/signup'') and I see no flash error message either. I just see an error page with the following dump. NameError in UsersController#create uninitialized constant UsersController::Activerecord RAILS_ROOT: /Users/apati/Projects/qa Application Trace | Framework Trace | Full Trace /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:492:in `const_missing'' app/controllers/users_controller.rb:24:in `create'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:1162:in `send'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:1162:in `perform_action_without_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:580:in `call_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:573:in `perform_action_without_benchmark'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ rescue.rb:201:in `perform_action_without_caching'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ caching/sql_cache.rb:13:in `perform_action'' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:in `cache'' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ query_cache.rb:8:in `cache'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ caching/sql_cache.rb:12:in `perform_action'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:529:in `send'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:529:in `process_without_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:569:in `process_without_session_management_support'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ session_management.rb:130:in `process'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:389:in `process'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb: 282:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb: 281:in `each'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb: 281:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb: 212:in `run'' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:502:in `load'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:502:in `load'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:354:in `new_constants_in'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:502:in `load'' /Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/commands/servers/ mongrel.rb:64 /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:in `require'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:354:in `new_constants_in'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:in `require'' /Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39 -e:2:in `load'' -e:2 Thanks, Amrita Are you trying to display flash[:error]? Nothing in the flash is> displayed magically. You have to decide to display it yourself (often > this happens in the application layout) > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 22, 12:43 am, amrita <amrita.p...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > But for the signup page, I still don''t get redirected to ''/login'' (Now > I have replaced this with ''/signup'') and I see no flash error message > either. I just see an error page with the following dump. > > NameError in UsersController#create > > uninitialized constant UsersController::ActiverecordThat''s because you''ve made a spelling mistake. Activerecord should be ActiveRecord Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Awesome! That was the problem! I should be more careful while typing. Thank you, Fred! On Jul 21, 4:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 22, 12:43 am, amrita <amrita.p...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > But for the signup page, I still don''t get redirected to ''/login'' (Now > > I have replaced this with ''/signup'') and I see no flash error message > > either. I just see an error page with the following dump. > > > NameError in UsersController#create > > > uninitialized constant UsersController::Activerecord > > That''s because you''ve made a spelling mistake. Activerecord should be > ActiveRecord > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---