tomkins
2012-Aug-14 12:31 UTC
validates_format_of :message not working, validates_length_of :message is working
I''m using validates_format_of and the validation I want to do works, but I can''t get an error message to be displayed if the data is invalid: validates_format_of :mobile, :with => /\A[\+0-9]+\Z/, :message => " - Wrong" I have another validation some where else that does display the error message: " - Name is too long" validates_length_of :name, :within => 5..40, :too_long => " - Name is too long", validates_length_of :name, :within => 1..50, :message => "Broken" *<------ This also works but not for validates_format_of* Any ideas? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/7jPE6lNPYBEJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Aug-14 12:40 UTC
Re: validates_format_of :message not working, validates_length_of :message is working
On 14 August 2012 13:31, tomkins <j.tomkins-EMRzualFZlQ@public.gmane.org> wrote:> I''m using validates_format_of and the validation I want to do works, but I > can''t get an error message to be displayed if the data is invalid: > validates_format_of :mobile, :with => /\A[\+0-9]+\Z/, :message => " - Wrong" > > I have another validation some where else that does display the error > message: " - Name is too long" > validates_length_of :name, :within => 5..40, :too_long => " - Name is too > long", > > validates_length_of :name, :within => 1..50, :message => "Broken" <------ > This also works but not for validates_format_ofYou say that you have an example of validates_length_of "somewhere else" that /does/ work. Are you sure that it is not the "somewhere else" that is significant. Try replacing the validates_length_of that is working with a validates_format_of and see if you then get the message. Also try replacing the format validation that does not show the error with a validates_length_of. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
tomkins
2012-Aug-14 13:06 UTC
Re: validates_format_of :message not working, validates_length_of :message is working
I tried what you suggested and I got the error message with validates_format_of where validates_length_of worked, and length_of didn''t work where my format_of wasn''t working. So it looks like the "somwhere else" is significant, but I cant see any obvious differences between the two models, any suggestions? Thanks for the help Colin. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ocNLoXufElwJ. For more options, visit https://groups.google.com/groups/opt_out.
tomkins
2012-Aug-14 13:24 UTC
Re: validates_format_of :message not working, validates_length_of :message is working
I fixed it, I was missing an <error-messages> tag in my edit code for the page that was not working. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/keaoGUocgQUJ. For more options, visit https://groups.google.com/groups/opt_out.