Hey people, I was wondering whether it''s possible to validate a text_field_tag which has nothing to do with the actual object being created? 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 -~----------~----~----~----~------~----~------~--~---
On Mar 17, 5:24 pm, Heinz Strunk <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey people, > > I was wondering whether it''s possible to validate a text_field_tag which > has nothing to do with the actual object being created? >validations are by definition a model centric thing. However there''s nothing stopping you doing if not_good(params[:some_text:]) ... else @record.save end Fred> Thanks > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you could also try...-CFSAjdWTiPz1P9xLtpHBDw@public.gmane.org_valid? which will validate w/o saving On Mar 17, 11:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 17, 5:24 pm, Heinz Strunk <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote:> Hey people, > > > I was wondering whether it''s possible to validate a text_field_tag which > > has nothing to do with the actual object being created? > > validations are by definition a model centric thing. However there''s > nothing stopping you doing > if not_good(params[:some_text:]) > ... > else > @record.save > end > > Fred > > > Thanks > > -- > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Heinz Strunk wrote:> Hey people, > > I was wondering whether it''s possible to validate a text_field_tag which > has nothing to do with the actual object being created? > > ThanksWhat about JavaScript? For example, I call a Vlaidation method onsubmit with a form when somebody creates a new object. Just a thought. -S -- 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 -~----------~----~----~----~------~----~------~--~---
Hey, both are actually pretty good approaches I think but I was hoping I could use that could use error_messages_for for the text_field_tag... that''s probably not the case? If I was using "if not_good(params..." I''d need to display it differently. It''d be extremly handy if I could just add an error to error_messages_for using "if not_good(..." -- 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 Mar 17, 10:04 pm, Heinz Strunk <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey, > > both are actually pretty good approaches I think but I was hoping I > could use that could use error_messages_for for the text_field_tag... > that''s probably not the case? > If I was using "if not_good(params..." I''d need to display it > differently. It''d be extremly handy if I could just add an error to > error_messages_for using "if not_good(..."You can call some_object.errors.add(...) to add errors to an activerecord object (you probably need to make the validations run first). Check out the errors class in the api. Fred> -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
But the text_field_tag has nothing to do with the @record so it wouldn''t help if I was checking if the @record is valid, right? tony wrote:> you could also try...-CFSAjdWTiPz1P9xLtpHBDw@public.gmane.org_valid? > > which will validate w/o saving > > On Mar 17, 11:00�am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Heinz, If you''re looking to invalidate the object based on this non-member field, you could use ActiveRecord.Errors.add_to_base() e.g. @record.errors.add_to_base("Invalid unpopple value") Then check validity with @record.errors.empty? Note that @record.is_valid will still return true (unless you override invalid? for the class). Hope that helps, James. 2009/3/17 Heinz Strunk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > But the text_field_tag has nothing to do with the @record so it wouldn''t > help if I was checking if the @record is valid, right? > > tony wrote: > > you could also try...-CFSAjdWTiPz1P9xLtpHBDw@public.gmane.org_valid? > > > > which will validate w/o saving > > > > On Mar 17, 11:00�am, Frederick Cheung <frederick.che...@gmail.com> > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
since your text field tag isn''t part of the model, you could instantiate the object with the value from the tag and then call is_valid and check the errors variable if you want the message. else you''ll have to write your own validation methods On Mar 17, 3:15 pm, Heinz Strunk <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> But the text_field_tag has nothing to do with the @record so it wouldn''t > help if I was checking if the @record is valid, right? > > tony wrote: > > you could also try...-CFSAjdWTiPz1P9xLtpHBDw@public.gmane.org_valid? > > > which will validate w/o saving > > > On Mar 17, 11:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Very nice. Very helpful. Thank you, James. Best regards, Bill On Tue, 2009-03-17 at 23:45 +0000, James Cowlishaw wrote:> Heinz, > > > If you''re looking to invalidate the object based on this non-member > field, you could use >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---