7 Replies Latest reply on Mar 27, 2014 12:20 AM by Mark Nongkhlaw

    Model initialization and validation?

    Arsen Bandurian

      Hi, All.

       

      With every piece of data come two (well, more, but let's concentrate on these for now) concerns:

      • How do I do initialization, when required?
      • How do I provide validation, when required?

       

      Assume, I have 'users' database: First name, Last name, login, password, bio.

      I want to ensure that login is unique, last/first names are present, password is of the certain length, and bio is set to 'Your bio here', when not explicitly provided.

      The logical place to do this is in the model.

       

      In Rails there were 'before:' and 'validates_..._of:' model statements, which allowed achieving this nice and clean. What is available in Rho? The documentation is silent on this.

       

      I tried redefining 'initialize' in model (which is called every time I call Model.new or Model.create) - this only brings all sorts of errors in rhom_object_factory.rb

      For validation I found this: Validations in Rhodes But it looks a bit old, and comments report all sorts of problems

       

      Will appreciate advice of both methodology (right and wrong things to do) and some code samples that show the framework.

       

      Thanks!