NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

cannot access field in nobrainer #148

Closed 34code closed 9 years ago

34code commented 9 years ago

gemfile

rethinkdb (>= 2.0.0.0) nobrainer (0.25.1)

I have a field called activated in User.rb model.

field :activated

and the following code:

def User.activated?
  self.activated
end

Yet I get the following error:

undefined methodactivated' for User:Class`

nviennot commented 9 years ago

Remove the User. in your code, otherwise, you are making a class method, not an instance method.

nviennot commented 9 years ago

and also, if you declare the field as :type => Boolean, this method will be automatically provided.

34code commented 9 years ago

If I remove User. , my controller throws an error:

undefined methodactivated?' for #`

btw thanks for the super fast reply :)

nviennot commented 9 years ago

ohh so you are looking to make a named scope then.

class User
  scope(:activated) { where(:activated => true) }
end

Or alternatively:

class User
  def self.activated
    where(:activated => true)
  end
end

You're welcome :)

34code commented 9 years ago

Not sure about this scope thing. That particular line gives me a syntax error in User.rb..

Everything was working great earlier and find_by was not deprecated and has_secure_password was working out of the box..

Now the new version released and it seems some things have broken. I would love to help more by debugging if I can. Is that scope line supposed to go in controller and not model as I assumed perhaps?

nviennot commented 9 years ago

Install http://tmate.io/ and share your terminal with me (send me the connection link via email) so I can help

34code commented 9 years ago

excellent! thanks :)