2nd one seems more like it Thanks On Fri, Mar 12, 2010 at 12:25 AM, mooman <[email protected]> wrote:
> Hi there, > > create method returns the same thing instance level save method > returns, because it calls that. > > so if validation fails it will return false unless you have > "raise_on_save_failure" set to true in your model, then it will raise > an error. > > so you can do like: > > c = Category.create do |c| > c.name = "" > end > > if c then > # pass validation, do something nice > else > # invalid, punish user > end > > or if you have it set to raise error, then: > > begin > Category.create do |c| > c.name = "" > end > rescue Sequel::ValidationFailed => error > # bad! > end > > hope that helps, > -mooman > > On Mar 10, 6:47 pm, hendra kusuma <[email protected]> wrote: > > Dear all, > > > > if I have model class : > > class Category < Sequel::Model(:categories) > > def validate > > errors.add(:name, "must not empty") if name.empty? > > end > > end > > > > then how I catch error from validate? Is it by adding rescue? Where to > put? > > > > Category.create do |c| > > c.name = "" > > end > > > > Thank you > > > > Regards > > Hendra > > > > -- > > Suka linux? > > Kunjungi blog sayahttp://penguinroad.blogspot.com > > -- > You received this message because you are subscribed to the Google Groups > "sequel-talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<sequel-talk%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/sequel-talk?hl=en. > > -- Suka linux? Kunjungi blog saya http://penguinroad.blogspot.com -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
