Max Williams
2007-Dec-14 11:49 UTC
using the session to pass a value from form to controller
I have a form in which a bunch of new users can be created with the same password if desired. I''m trying to write the password into the session and pull it out in the controller (besides avoiding putting it into params, this also should let me keep it for repopulating the text field if the creation fails for any reason and the user gets sent back to the page with the form). As part of a form tag, i have this text field which is supposed to write the value entered in it into the session <% form_tag :action => ''batch_save'', :id => @user do %> .. <p>Password:<%= text_field_tag :password, session[''new_users_password''] %> .. <%= submit_tag ''Save'' %></p> <% end -%> But, in the batch_save method in the controller, when i evaluate session[''new_users_password''], i get nil back. Can anyone see what i''m doing wrong? thanks max -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Dec-14 11:55 UTC
Re: using the session to pass a value from form to controlle
<p>Password:<%= text_field_tag :password, session[''new_users_password''] will create a textfield in html output (the browser does not know anything about the rails session hash, anyway) this will be handed to your controller as every other form data in params[] so params[:password] is the thing to use eg: session[:new_user_password] = params[:password] -- 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 -~----------~----~----~----~------~----~------~--~---
Max Williams
2007-Dec-14 12:21 UTC
Re: using the session to pass a value from form to controlle
Thorsten Mueller wrote:> <p>Password:<%= text_field_tag :password, session[''new_users_password''] > > will create a textfield in html output (the browser does not know > anything about the rails session hash, anyway) > this will be handed to your controller as every other form data in > params[] > > so params[:password] is the thing to use eg: > session[:new_user_password] = params[:password]ah. cool, i''ve written the value from params into the session in the controller and it''s fine now. thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Dec-14 12:46 UTC
Re: using the session to pass a value from form to controller
On Dec 14, 2007, at 12:49 PM, Max Williams wrote:> I have a form in which a bunch of new users can be created with the > same > password if desired. I''m trying to write the password into the > session > and pull it out in the controller (besides avoiding putting it into > params, this also should let me keep it for repopulating the text > field > if the creation fails for any reason and the user gets sent back to > the > page with the form). > > As part of a form tag, i have this text field which is supposed to > write > the value entered in it into the session > > <% form_tag :action => ''batch_save'', :id => @user do %> > .. > <p>Password:<%= text_field_tag :password, > session[''new_users_password'']Why would you need the session? My interpretation of the feature is that you set as default the password of the last created user. If that was the case, you are done passing params[:password] for that field no matter whether the creation of the user of that request is successful or not. If the creation is successful that''s clear. If not and the user edited the password and email validation failed you do not want to set the default password back, you want to let him correct the email and still set the password he chose, so params[:password] makes sense there as well. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---