the validates_format and other validations are called when the .save function is called on an object. If I want the validations to be called without saving is there a way to do this? Do I user .create? Thank you in advance for your time. Mitch -- 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 -~----------~----~----~----~------~----~------~--~---
If you just want to know whether a model is valid, ask it: model.valid? That will run the validations, populate model.errors and return true/false. Is there something else that you want to do? Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can just create a new object @user = User.new(params[:user]) and then check with @user.valid? a User.create would create, validate and save in one go, what''s exactly what you wanted to avoid --~--~---------~--~----~------------~-------~--~----~ 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 wrote:> You can just create a new object > > @user = User.new(params[:user]) > > and then check with > > @user.valid? > > > a User.create would create, validate and save in one go, > what''s exactly what you wanted to avoidThank you very much Thorsten that will do the trick. Mitch -- 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> If you just want to know whether a model is valid, ask it: > model.valid? That will run the validations, populate model.errors and > return true/false. Is there something else that you want to do? > > Regards, > CraigThanks Craig that answers my question. I would do in the user controller def registration If model.valid? redirect_to :action => ''user_details'' end #otherwise it will go back to the user registration page automatically? #The form will show the error_messages_for :user correct? end something like that look about right? -- 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 -~----------~----~----~----~------~----~------~--~---
On Fri, Jul 4, 2008 at 11:53 AM, Mitchell Gould <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks Craig that answers my question. > I would do in the user controller > > def registration > > If model.valid? > > redirect_to :action => ''user_details'' > > end > > > #otherwise it will go back to the user registration page automatically? > #The form will show the error_messages_for :user correct? > end > > something like that look about right?Things like the redirect to the user registration page won''t happen automatically because you call model.valid?; you''ll have to make it happen by putting it in a branch of your conditional logic, for example. Also, while the error messages will be displayed in the view if you use the error_messages_for helper, the helper may display an empty but colored div if there are no errors, and you probably don''t want that. That''s also something that you''ll have to try and then handle however you want to handle it yourself. If you''re doing a multi-step process, you might want to check out _Advanced Rails Recipes _ [ http://pragprog.com/titles/fr_arr/advanced-rails-recipes ], which has a "Create Multi-Step Wizards" recipe. Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> On Fri, Jul 4, 2008 at 11:53 AM, Mitchell Gould > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> #otherwise it will go back to the user registration page automatically? >> #The form will show the error_messages_for :user correct? >> end >> >> something like that look about right? > > Things like the redirect to the user registration page won''t happen > automatically because you call model.valid?; you''ll have to make it > happen by putting it in a branch of your conditional logic, for > example. Also, while the error messages will be displayed in the view > if you use the error_messages_for helper, the helper may display an > empty but colored div if there are no errors, and you probably don''t > want that. That''s also something that you''ll have to try and then > handle however you want to handle it yourself. > > If you''re doing a multi-step process, you might want to check out > _Advanced Rails Recipes _ [ > http://pragprog.com/titles/fr_arr/advanced-rails-recipes ], which has > a "Create Multi-Step Wizards" recipe. > > Regards, > CraigThats very helpful. I really appreciate the info and will check it out. thanks again! MItch -- 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 -~----------~----~----~----~------~----~------~--~---