Rhomobile model error - Undefined method

B Benj Bouch 3 years 7 months ago
4 3 0

Greetings,

I get the error undefined method 'find' for Auth:Class on this code:

class Auth
  include Rhom::FixedSchema

  set :schema_version, '0.1'

  property :field1, :string
  property :field2, :string

  def self.auth_record
    @auth_record ||= begin
      if find(:count) == 0 # This is the line raising the error
        create
      else
        find :first
      end
    end
  end
end

Also when inspecting Auth.ancestors I got this output [Auth, Rhom::FixedSchema, Rhom::BaseModel, Object, JSON::Pure::Generator::GeneratorMethods::Object, Kernel, BasicObject]

I did follow the doc strictly, and cannot find any info on google. Any help greatly appreciated

Please Register or Login to post a reply

3 Replies

B Benj Bouch

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.

Thanks to those who provided me with help.
Regards

J Jon Tara

What the heck is this?!

  @auth_record ||= begin

And what are you trying to do here?

  if find(:count) == 0

I think it's too soon to try to use the database at that point - it hasn't been created yet!

K Kutir Mobility

Hi Benj,
What version of RhoMobile you use and at what point you get this error?

Visnupriya RKutir Mobility

CONTACT
Can’t find what you’re looking for?