On 9 February 2011 01:59, jackster the jackle <[email protected]> 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!

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::RecordInvalid

More 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"=>"[email protected]"},
> "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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to