In Rails < 3, I could have a validation on model such as: validates_presence_of :name, :message => "some custom message here" If I try something similar in Rails 3: validates :name, :presence => true , :message => "some other custom message" obviously, it throws an exception. So the question is, in Rails 3, how to you give a simple custom message? Do I need to go through and set up a custom validation class for each validation, just to show a different message? I''ve looked at: http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validations/ClassMethods.html#M003721 but it seems to show that a custom class would need to be set up for each attribute of my models? I''m sure there''s a shortcut, but have yet to find it. 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-/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.
v On Sun, Oct 3, 2010 at 12:07 PM, John T. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In Rails < 3, I could have a validation on model such as: > > validates_presence_of :name, :message => "some custom message here" > > If I try something similar in Rails 3: > > validates :name, :presence => true , :message => "some other custom > message" >validates :name, :presence => {"some other custom"} most options are now passed like that , for example validates :name, :unique => {:scope => :company_id} you see, options are now passed as hashes to the validation key -- 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.
radhames brito wrote:> > validates :name, :presence => {"some other custom"} > > most options are now passed like that , for example > > > validates :name, :unique => {:scope => :company_id} > > you see, options are now passed as hashes to the validation keyYeah, I did see that, but I don''t see any options for what I want to do. The syntax you gave, however throws a syntax error. -- 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.
Hello John, In Rails 3 also validates_presence_of is present. Why you are not using this one? validates_presence_of :name, :message => "some custom message here" Thanks! Butu On Mon, Oct 4, 2010 at 1:27 PM, John T. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> radhames brito wrote: > > > > > validates :name, :presence => {"some other custom"} > > > > most options are now passed like that , for example > > > > > > validates :name, :unique => {:scope => :company_id} > > > > you see, options are now passed as hashes to the validation key > > Yeah, I did see that, but I don''t see any options for what I want to do. > The syntax you gave, however throws a syntax error. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello. Try this: validates :name, :presence => { :message => "My custom message" } On Oct 3, 7:07 pm, "John T." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In Rails < 3, I could have a validation on model such as: > > validates_presence_of :name, :message => "some custom message here" > > If I try something similar in Rails 3: > > validates :name, :presence => true , :message => "some other custom > message" > > obviously, it throws an exception. So the question is, in Rails 3, how > to you give a simple custom message? Do I need to go through and set up > a custom validation class for each validation, just to show a different > message? I''ve looked at: > > http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validati... > > but it seems to show that a custom class would need to be set up for > each attribute of my models? I''m sure there''s a shortcut, but have yet > to find it. > > 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-/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.
Butu wrote:> Hello John, > > In Rails 3 also validates_presence_of is present. Why you are not using > this > one? > > validates_presence_of :name, :message => "some custom message here" > > Thanks! > ButuHi, I am aware the original version is available, but I was trying to update to the new validators in Rails 3. I guess I''m going to just have to ditch that and go back to the old. Seems to be another "New and Shiny" way of doing things, but lose simple functionality... ;) -- 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.
On Sun, Oct 3, 2010 at 10:27 PM, John T. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> radhames brito wrote: > > > > > validates :name, :presence => {"some other custom"} > > > > most options are now passed like that , for example > > > > > > validates :name, :unique => {:scope => :company_id} > > > > you see, options are now passed as hashes to the validation key > > Yeah, I did see that, but I don''t see any options for what I want to do. > The syntax you gave, however throws a syntax error. > >validates :name, :presence => { :message => "hello world" } what is it you want to do ? -- 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.
Radhames Brito wrote:> On Sun, Oct 3, 2010 at 10:27 PM, John T. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> > you see, options are now passed as hashes to the validation key >> >> Yeah, I did see that, but I don''t see any options for what I want to do. >> The syntax you gave, however throws a syntax error. >> >> > validates :name, :presence => { :message => "hello world" } > > what is it you want to do ?Ahhhh... I didn''t have quite the right syntax. That seems to work. I''m just trying to give a custom error message if an attribute is blank, besides the normal "can''t be blank". 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-/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.