Hi, I am developing an application in rails 3.0 I have post Model class Post < ActiveRecord::Base validates :name , :presence => true end I have added the presence of validation on post name. It shows me error that "Name can''t be blank" I have to give the custom message for the user so I have written like as follows:- class Post < ActiveRecord::Base validates :name , :presence => true , :message=>"Post name can''t be blank." end But it is giving me error:- "Unknown validator: ''message''" Can anyone tell me How to give the custom message in rails 3 model validations? Thanks, Mike -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Edmond Kachale
2010-Sep-20 13:10 UTC
Re: Adding custom message on model validation in rails 3
I think differently: Why can''t you use JavaScript to check for a blank field? Regards, --- Edmond Software Developer | Baobab Health Trust (http://www.baobabhealth.org/) | Malawi Cell: +265 999 465 137 | +265 881 234 717 *"Many people doubt open source software and probably don’t realize that there is an alternative… which is just as good.." -- Kevin Scannell* 2010/9/20 Mike Disuza <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> Hi, > I am developing an application in rails 3.0 > > I have post Model > class Post < ActiveRecord::Base > validates :name , :presence => true > end > > I have added the presence of validation on post name. > It shows me error that "Name can''t be blank" > > I have to give the custom message for the user so I have written like as > follows:- > > class Post < ActiveRecord::Base > validates :name , :presence => true , :message=>"Post name can''t be > blank." > end > > But it is giving me error:- > "Unknown validator: ''message''" > > Can anyone tell me How to give the custom message in rails 3 model > validations? > > Thanks, > Mike > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mike Disuza
2010-Sep-20 13:38 UTC
Re: Adding custom message on model validation in rails 3
Hey, I don''t want to use the javascript, as rails directly provides us validations then why should we write code. Is there anyone know how to add custom message on model validation in rails 3.0.0 Thanks, Mike. -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maksim Gudovsikov
2010-Sep-20 14:18 UTC
Re: Adding custom message on model validation in rails 3
Hi, try the following: class Post < ActiveRecord::Base validates :name , :presence => { :message=>"Post name can''t be blank." } end Maksim. Am 20.09.2010 14:49, schrieb Mike Disuza:> Hi, > I am developing an application in rails 3.0 > > I have post Model > class Post < ActiveRecord::Base > validates :name , :presence => true > end > > I have added the presence of validation on post name. > It shows me error that "Name can''t be blank" > > I have to give the custom message for the user so I have written like as > follows:- > > class Post < ActiveRecord::Base > validates :name , :presence => true , :message=>"Post name can''t be > blank." > end > > But it is giving me error:- > "Unknown validator: ''message''" > > Can anyone tell me How to give the custom message in rails 3 model > validations? > > Thanks, > Mike-- Maksim Gudovsikov webit! Gesellschaft für neue Medien mbH Schnorrstraße 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 gudovsikov-jv+WEUQhfkc@public.gmane.org | www.webit.de Amtsgericht Dresden | HRB 15422 USt-ID DE 193477690 Geschäftsführer Sven Haubold -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Sep-20 17:47 UTC
Re: Adding custom message on model validation in rails 3
Please quote when replying. Edmond Kachale wrote:> I think differently: Why can''t you use JavaScript to check for a blank > field?No way! JavaScript validations should never be relied on -- it''s too easy for the client to turn them off and bypass them, or to submit a crafted GET or POST request that bypasses the HTML form entirely. Validation *must* be done on the server side.> > Regards, > > --- > EdmondBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mike Disuza
2010-Sep-23 10:09 UTC
Re: Adding custom message on model validation in rails 3
Hi, Your solution is working but the message is coming like this:- "Name Post name can''t be blank." My model post.rb is:- class Post < ActiveRecord::Base validates :name , :presence => { :message=>"Post name can''t be blank."} validates :title, :presence => true, :length => { :minimum => 5 } has_many :comments , :dependent => :destroy end -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Sep-23 10:21 UTC
Re: Re: Adding custom message on model validation in rails 3
On 23 September 2010 11:09, Mike Disuza <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > Your solution is working but the message is coming like this:-What solution, from whom? You did not quote the previous message so no-one knows what you are talking about. Colin> > "Name Post name can''t be blank." > > My model post.rb is:- > > class Post < ActiveRecord::Base > validates :name , :presence => { :message=>"Post name can''t be > blank."} > validates :title, :presence => true, :length => { :minimum => 5 } > has_many :comments , :dependent => :destroy > end-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mike Disuza
2010-Sep-23 12:15 UTC
Re: Re: Adding custom message on model validation in rails 3
Yes. I am talking about the Maksim solution. -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maksim Gudovsikov
2010-Sep-23 12:37 UTC
Re: Re: Adding custom message on model validation in rails 3
Hi, it''s the default error_message_on behavior. You can try to override it. Another solution could be to write your message without the attribute: just "can''t be blank.", so you get "Name can''t be blank". Hope it helps you. Regards, Maksim. Am 23.09.2010 12:09, schrieb Mike Disuza:> Hi, > Your solution is working but the message is coming like this:- > > "Name Post name can''t be blank." > > My model post.rb is:- > > class Post < ActiveRecord::Base > validates :name , :presence => { :message=>"Post name can''t be > blank."} > validates :title, :presence => true, :length => { :minimum => 5 } > has_many :comments , :dependent => :destroy > end-- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.