AFAIK, form_for need the @user object to determine the url. if its a new then it would generate /users and POST method if its already exist it generate /users with PUT method
i think that you can specify the URL like daze said, if you create new @user, it wil redirect to create method (if you have REST route) unless you specify the route otherwise On Tue, Dec 21, 2010 at 7:41 AM, John Merlino <[email protected]> wrote: > Hey all, > > I know that this: > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > means that I have an instance variable that has not been initialized. > However, I'm a little confused as to what to do in a signup form for > form_for: > > <% content_for :login do %> > <% form_for @user, :url => { :action => "login" } do |f| %> > <%= error_messages_for 'user' %><br/> > <%= f.label(:user_login, "Username")%> > <%= f.text_field(:login) %><br/> > <%= f.label(:user_password, "User Password")%> > <%= f.password_field(:password) %><br/> > <%= f.submit("Sign Up") %> > > <%= link_to 'Register', :action => 'signup' %> | > <%= link_to 'Forgot my password', :action => 'forgot_password' %> > <% end %> > <% end %> > > Because I didn't declare @user in login method: > > def login > if request.post? > if session[:user] = User.authenticate(params[:user][:login], > params[:user][:password]) > flash[:message] = "Login successful" > redirect_to_root > else > flash[:warning] = "Login unsuccessful" > end > end > > end > > There is no @user and so interpreter throws the exception. However, what > can I do in order to allow someone the opportunity to signin when using > a form? Do I create a temporary blank user: @user = User.new? > > Thanks for response. > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<rubyonrails-talk%[email protected]> > . > 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 [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.

