0

Following the documentation I am trying to create my first model in Rhomobile 4.1.1

It is advised to create a Ruby class, and said that the framework would create the necessary table. But I must have misunderstood because it is not working that way.

model in app/Auth/auth.rb

class Auth
  include Rhom::FixedSchema

  set :schema_version, '0.1'

  property :session_token, :string
  property :remember_token, :string

  def self.auth_record
    @auth_record ||= begin
      if find(:count) == 0
        create
      else
        find :first
      end
    end
  end

end

As you can see I am trying to create a fixed schema single record table. I am not using RhoSync. As a result there is no table created, I am missing a step. Any hint appreciated. Thanks

Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73

1 Answers1

1

My mistake was to have

require 'Auth/auth'

On top of one of my files.

The framework relies on const_missing to load and initialize the model (inject dependencies, create tables, ...). As I explicitly required the source file, the constant was already defined therefore Rhodes internal did not perform the needed initialization. Removing the require fixed the problem.

Lesson learned, also I would says that 1) this is not really solid coding and 2) this is completely undocumented.

Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73