Flash[:error] not displayed

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

On 21 Jul 2008, at 23:52, amrita wrote:

flash[:notice] works all right. Here is the code snippet from the
controller for users where I observe the difference in behaviors.

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

On Jul 22, 12:43 am, amrita [email protected] 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

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:increate’
/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:inperform_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:inperform_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:inperform_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:inperform_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:incache’
/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:insend’
/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:inprocess_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:inprocess’
/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:insynchronize’
/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:inprocess_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:inprocess_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:ininitialize’
/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:inrun’
/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:innew’
/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:inrun’
/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:inrun’
/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:inrun’
/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:inload’
/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:inload’
/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:innew_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:inload’
-e:2

Thanks,
Amrita

Are you trying to display flash[:error]? Nothing in the flash is

Awesome! That was the problem! I should be more careful while typing.
Thank you, Fred!

On Jul 21, 4:50 pm, Frederick C. [email protected]