Hello.. I wanted to extend my webpage's user interaction by allowing
users to register themselves. The account controller method "register"
takes care of the process. This is the register.rhtml code i wrote in
apps/views/accounts/register.rhtml :
The register method in the account controller looks like :
def register
@u = User.new(params[:login])
@u = @current_user
if request.post? and @u.save@current_user = User.new(params[:login])
flash[:notice] = 'Registration succeeded'
redirect_to :controller => 'story', :action => 'index'
end
end
The problem it gives a nil object error for the statement @u.save . I
donot understand since when im breakpointing ...$params shows that it
holds the entire submitted form values ...but $params[:login] => nil
$params[:name] => nil
where is the all the data going and why is it not getting saved. please
help
so most likely @u = @current_user sets @u to nil,
since @current_user isn't set before that. In any case
you would lose the newly created user.
And you should NEVER use variable names like @u
that do not tell what they are good for...
Thorsten..
was getting bugged rewriting the name .. so was using "u" .. i know its
a bad habit.. so changed it..
anyways .. i applied the changes and the story saves..thanks..
but all the fields are being set to null. i mean the values the user
enters for login password in registration page are all being set to null
instead of what was enterd ...
weird .. eh ?? is their a prob with the form_for object ?
no, there is no problem with form_for
but you're using params[:login] instead of params[:user]
a form like this has a params hash named as the model the form is made
for
the single fields are used then like:
params[:user][:login]
in your case
User.new(params[:user])
should work