If using recipe 31 in Mr. Fowler''s book, one ought really to add a form for user creation. Something like this (within user_controller.rb), perhaps: def register @user = User.create if request.post? @user.attributes = params[:user] if @user.save flash[:notice] = "Your request has been saved." redirect_to :controller => ''user'', :action => ''register_success'', :user => @user.id and return else flash[:error] = "Your request could not be saved." redirect_to :controller => ''user'', :action => ''register'', :method => ''get'' and return end end end The way the user model works is that it does not store the user''s password, but the password_salt and password_hash. The password method generates these. A means of checking that the password and confirmation from the form in register.rhtml match, and that the password consists of the approved characters is needed. What would be the best place to put this - in the user model or as part of this register method? If the latter, does anyone have any suggestions as to a good way to do this? -- 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 -~----------~----~----~----~------~----~------~--~---
IMO, validation always belongs in the model. On Sep 11, 8:14 am, Milo Thurston <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> If using recipe 31 in Mr. Fowler''s book, one ought really to add a form > for user creation. Something like this (within user_controller.rb), > perhaps: > > def register > @user = User.create > if request.post? > @user.attributes = params[:user] > if @user.save > flash[:notice] = "Your request has been saved." > redirect_to :controller => ''user'', :action => ''register_success'', > :user => @user.id and return > else > flash[:error] = "Your request could not be saved." > redirect_to :controller => ''user'', :action => ''register'', :method > => ''get'' and return > end > end > end > > The way the user model works is that it does not store the user''s > password, but the password_salt and password_hash. The password method > generates these. A means of checking that the password and confirmation > from the form in register.rhtml match, and that the password consists of > the approved characters is needed. > > What would be the best place to put this - in the user model or as part > of this register method? If the latter, does anyone have any suggestions > as to a good way to do this? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Jeff Emminger wrote:> IMO, validation always belongs in the model.Thanks - I will indeed put it there. -- 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 -~----------~----~----~----~------~----~------~--~---
Milo Thurston wrote:> The way the user model works is that it does not store the user''s > password, but the password_salt and password_hash. The password method > generates these. A means of checking that the password and confirmation > from the form in register.rhtml match, and that the password consists of > the approved characters is needed. > > What would be the best place to put this - in the user model or as part > of this register method? If the latter, does anyone have any suggestions > as to a good way to do this?If you have a chance to pick up the Agile Web Development with Rails book from the same publisher, there is similar code included in chapter 11. The validation is enforced by the model (via validates_presence_of, et. al.) while the action of saving and displaying the resulting message is done in the controller. I''ve been carrying that book around with me anywhere I go for the last month :) -- 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 -~----------~----~----~----~------~----~------~--~---