Since I upgraded from Rails 1.8.6 to 2.3.5, I just noticed that I can no longer add new users through my Signup page. Here is the error: NoMethodError in UserController#signup You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.save! /work/store/app/controllers/user_controller.rb:6:in `signup'' Here is my Controller, line 6 is @user.save!: def signup return unless request.post? @user.save! redirect_back_or_default(:controller => ''grapher'', :action => ''index'') flash[:notice] = "New User Successfully Created" rescue ActiveRecord::RecordInvalid render :action => ''signup'' end Here is my form: <% form_for :user do |f| -%> <label for= "first_name">First Name</label> <%= f.text_field :first_name %> <label for= "last_name">Last Name</label> <%= f.text_field :last_name %> <label for= "user_login">Login</label> <%= f.text_field :login %> <label for= "user_email">Email</label> <%= f.text_field :email %> <label for= "user_password">Password</label> <%= f.password_field :password %> <label for= "user_password_confirmation">Confirm Password</label> <%= f.password_field :password_confirmation %> <%= submit_tag ''Sign up'' %> <% end -%> Here are my request parameters when I get the error: Request Parameters: {"user"=>{"password_confirmation"=>"password", "first_name"=>"john", "last_name"=>"smith", "login"=>"jsmith", "password"=>"password", "email"=>"jsmith-zuv13RyHHZkAvxtiuMwx3w@public.gmane.org"}, "commit"=>"Sign up"} It seems to me that I''m passing the correct params so I don''t understand why I''m getting a "nil object" error? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Do you have a before filter where you set the @user variable? It''s complaining that the @user variable is nil. On Wed, Feb 9, 2011 at 9:59 AM, jackster the jackle <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Since I upgraded from Rails 1.8.6 to 2.3.5, I just noticed that I can no > longer add new users through my Signup page. > Here is the error: > NoMethodError in UserController#signup > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.save! > > /work/store/app/controllers/user_controller.rb:6:in `signup'' > > Here is my Controller, line 6 is @user.save!: > def signup > return unless request.post? > @user.save! > redirect_back_or_default(:controller => ''grapher'', :action => > ''index'') > flash[:notice] = "New User Successfully Created" > rescue ActiveRecord::RecordInvalid > render :action => ''signup'' > end > > Here is my form: > <% form_for :user do |f| -%> > <label for= "first_name">First Name</label> > <%= f.text_field :first_name %> > > <label for= "last_name">Last Name</label> > <%= f.text_field :last_name %> > > <label for= "user_login">Login</label> > <%= f.text_field :login %> > > <label for= "user_email">Email</label> > <%= f.text_field :email %> > > <label for= "user_password">Password</label> > <%= f.password_field :password %> > > <label for= "user_password_confirmation">Confirm Password</label> > <%= f.password_field :password_confirmation %> > <%= submit_tag ''Sign up'' %> > <% end -%> > > Here are my request parameters when I get the error: > Request > Parameters: > > {"user"=>{"password_confirmation"=>"password", > "first_name"=>"john", > "last_name"=>"smith", > "login"=>"jsmith", > "password"=>"password", > "email"=>"jsmith-zuv13RyHHZkAvxtiuMwx3w@public.gmane.org"}, > "commit"=>"Sign up"} > > It seems to me that I''m passing the correct params so I don''t understand > why I''m getting a "nil object" error? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No, I don''t have any before statements in my controller, here is what it looks like: class UserController < ApplicationController public def signup return unless request.post? @user.save! redirect_back_or_default(:controller => ''grapher'', :action => ''index'') flash[:notice] = "New User Successfully Created" rescue ActiveRecord::RecordInvalid render :action => ''signup'' end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
How do you assign the user params to the @user object? Try adding before the @user.save! line the following @user = User.new params[:user] On Wed, Feb 9, 2011 at 10:57 AM, jackster the jackle <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> No, I don''t have any before statements in my controller, here is what it > looks like: > > class UserController < ApplicationController > > public > def signup > return unless request.post? > @user.save! > redirect_back_or_default(:controller => ''grapher'', :action => > ''index'') > flash[:notice] = "New User Successfully Created" > rescue ActiveRecord::RecordInvalid > render :action => ''signup'' > end > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
When I add that line to the top of my "def signup" code in the controller, I no longer get my signup form, instead, I get this message instead of seeing all the fields in my signup form: NoMethodError in UserController#signup You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] jack -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 February 2011 01:59, jackster the jackle <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Since I upgraded from Rails 1.8.6 to 2.3.5, I just noticed that I can no > longer add new users through my Signup page. > Here is the error: > NoMethodError in UserController#signup > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.save! > > /work/store/app/controllers/user_controller.rb:6:in `signup'' > > Here is my Controller, line 6 is @user.save!: > def signup > return unless request.post? > -uQpvtAwYA0+zQB+pC5nmwQ@public.gmane.org!The error is telling you that @user is nil. There does not appear to be any code setting this up, Are you sure it ever worked?> redirect_back_or_default(:controller => ''grapher'', :action => > ''index'') > flash[:notice] = "New User Successfully Created"This code also looks odd, how will it get to the flash line after the redirect? Though I may be missing what redirect_back_or_default is supposed to do.> rescue ActiveRecord::RecordInvalidMore odd looking code, or did the syntax for rescue change dramatically with Rails 2 from Rails 1> render :action => ''signup'' > end > > Here is my form: > <% form_for :user do |f| -%> > <label for= "first_name">First Name</label> > <%= f.text_field :first_name %> > > <label for= "last_name">Last Name</label> > <%= f.text_field :last_name %> > > <label for= "user_login">Login</label> > <%= f.text_field :login %> > > <label for= "user_email">Email</label> > <%= f.text_field :email %> > > <label for= "user_password">Password</label> > <%= f.password_field :password %> > > <label for= "user_password_confirmation">Confirm Password</label> > <%= f.password_field :password_confirmation %> > <%= submit_tag ''Sign up'' %> > <% end -%> > > Here are my request parameters when I get the error: > Request > Parameters: > > {"user"=>{"password_confirmation"=>"password", > "first_name"=>"john", > "last_name"=>"smith", > "login"=>"jsmith", > "password"=>"password", > "email"=>"jsmith-zuv13RyHHZkAvxtiuMwx3w@public.gmane.org"}, > "commit"=>"Sign up"}What action does the log show this is going to?> > It seems to me that I''m passing the correct params so I don''t understand > why I''m getting a "nil object" error?I think because @user is not getting setup. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 9 Feb 2011, at 06:51, jackster the jackle <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> When I add that line to the top of my "def signup" code in the > controller, > I no longer get my signup form, instead, I get this message instead of > seeing all the fields in my signup form: >You''d want to put it after the check for request.post? Like some others here, i''m surprised this ever worked Fred> NoMethodError in UserController#signup > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > > jack > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > >> redirect_back_or_default(:controller => ''grapher'', :action => >> ''index'') >> flash[:notice] = "New User Successfully Created" > > This code also looks odd, how will it get to the flash line after the > redirect? Though I may be missing what redirect_back_or_default is > supposed to do.Calls to redirect, render etc. don''t terminate the action so there''s nothing very wrong about this (don''t know if the rails 3.1 changes to flushing will change this)> >> rescue ActiveRecord::RecordInvalid > > More odd looking code, or did the syntax for rescue change > dramatically with Rails 2 from Rails 1 >That''s just standard ruby. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 February 2011 08:27, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > rescue ActiveRecord::RecordInvalid > > More odd looking code, or did the syntax for rescue change > dramatically with Rails 2 from Rails 1 > > That''s just standard ruby.I thought you had to have begin ... rescue ... end Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I changed the order of my "def signup" as follows: class UserController < ApplicationController public def signup return unless request.post? @user = User.new(@params[:user]) @user.save! redirect_back_or_default(:controller => ''grapher'', :action => ''index'') flash[:notice] = "New User Successfully Created" rescue ActiveRecord::RecordInvalid render :action => ''signup'' end .. and now my form page comes up but still get this error message when I hit submit: NoMethodError in UserController#signup You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] thanks jack -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 February 2011 11:49, jackster the jackle <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I changed the order of my "def signup" as follows: > > class UserController < ApplicationController > > public > def signup > return unless request.post? > @user = User.new(@params[:user])It should be params[..] not @params[..] I thought you said the code worked before you upgraded. I also suggest you have a look at the Rails Guide on debugging (and the other guides in fact). That will show you how to use ruby-debug to break into the code and inspect the data. In this case, for example, you could have broken in before the @user= line and you would see that @params was nil, which would have made you look more closely at it and realise the typo. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On Feb 9, 8:42 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > I thought you had to have > begin > ... > rescue > ... > enddef some_method ... rescue ... end works too 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 9 February 2011 12:07, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Feb 9, 8:42 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> I thought you had to have >> begin >> ... >> rescue >> ... >> end > > def some_method > ... > rescue > ... > end > > works tooOnce again the trivial extent of my knowledge is exposed :) No doubt that is documented somewhere in the Ruby docs, but it did not leap out at me from anywhere I looked. Thanks Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.