this is the bit of code i''m having a problem with.. the odd thing.. if i remove all the code in the def login, reload the page so the view actually shows up put the code back in the def login and submit the form.. it works just fine... but if i start with the code for the login in the controller then it''s broken and starts giving me the errors posted below. def login if session[:user] = User.authenticate(params[:user][:login], params[:user][:password]) redirect_to :controller => ''user'', :action => ''pist'' else redirect_to :controller => ''user'', :action => ''mane'' end end because it is producing this. NoMethodError in UserController#login You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[] RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace /Users/morgan/Sites/born/app/controllers/user_controller.rb:21:in `login'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:1101:in `send'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:1101:in `perform_action_without_filters'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:696:in `call_filters'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:688:in `perform_action_without_benchmark'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/rescue.rb:83:in `perform_action'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in `send'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in `process_without_filters'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:684:in `process_without_session_management_support'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/session_management.rb:114:in `process'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:334:in `process'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/dispatcher.rb:41:in `dispatch'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in `process'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `synchronize'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `process'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/commands/servers/mongrel.rb:60 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/commands/server.rb:39 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'' script/server:3 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 14, 5:59 pm, Morgan Morgan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> this is the bit of code i''m having a problem with.. the odd thing.. if > i remove all the code in the def login, reload the page so the view > actually shows up put the code back in the def login and submit the > form.. it works just fine... but if i start with the code for the > login in the controller then it''s broken and starts giving me the errors > posted below.Assuming that you have a single login action that both displays the form and submits it then the problem is that if there are no parameters then params[:user] will be nil and so params[:user][:login] is nonsensical. When you submit the form however the parameters will be there and so there''s no problem. One way to deal with this would be to surround the relevant parts with if request.post? ... Fred> > def login > > if session[:user] = User.authenticate(params[:user][:login], > params[:user][:password]) > redirect_to :controller => ''user'', :action => ''pist'' > else > redirect_to :controller => ''user'', :action => ''mane'' > end > > end > > because it is producing this. > > NoMethodError in UserController#login > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.[] > > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > > /Users/morgan/Sites/born/app/controllers/user_controller.rb:21:in > `login'' > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/base.rb:1101:in > `send'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/base.rb:1101:in > `perform_action_without_filters'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:696:in > `call_filters'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:688:in > `perform_action_without_benchmark'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in > `perform_action_without_rescue'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/ben chmark.rb:293:in > `measure'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in > `perform_action_without_rescue'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/rescue.rb:83:in > `perform_action'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in > `send'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in > `process_without_filters'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:684:in > `process_without_session_management_support'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/session_management.rb:114:in > `process'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/actionpack-1.13.6/lib/action_controller/base.rb:334:in > `process'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/rails-1.2.6/lib/dispatcher.rb:41:in > `dispatch'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in > `process'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in > `synchronize'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in > `process'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in > `process_client'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in > `each'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in > `process_client'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in > `initialize'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in > `new'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in > `initialize'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in > `new'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in > `each'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in > `run'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/mongrel-1.1.4/bin/mongrel_rails:281 > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in > `load'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in > `load'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in > `load'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/rails-1.2.6/lib/commands/servers/mongrel.rb:60 > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub ygems/custom_require.rb:27:in > `gem_original_require'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub ygems/custom_require.rb:27:in > `require'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1. 8/gems/rails-1.2.6/lib/commands/server.rb:39 > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub ygems/custom_require.rb:27:in > `gem_original_require'' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub ygems/custom_require.rb:27:in > `require'' > script/server:3 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> if session[:user] = User.authenticate(params[:user][:login], params[:user][:password])What is this line of code supposed to do? The syntax seems to me completely wrong, hence Rails blowing on you. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Jul 14, 5:59�pm, Morgan Morgan <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> > wrote: >> this is the bit of code i''m having a problem with.. �the odd thing.. �if >> i remove all the code in the def login, �reload the page so the view >> actually shows up put the code back in the def login and submit the >> form.. �it works just fine... � but if i start with the code for the >> login in the controller then it''s broken and starts giving me the errors >> posted below. > > Assuming that you have a single login action that both displays the > form and submits it then the problem is that if there are no > parameters then params[:user] will be nil and so params[:user][:login] > is nonsensical. When you submit the form however the parameters will > be there and so there''s no problem. > One way to deal with this would be to surround the relevant parts with > if request.post? ... > > > Fredi thought that made sense... i just didn''t know how to do it.. thank you..... FIXED. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---