Class: Kwipper::User
Constant Summary
Constants inherited from Model
Model::DB_FILE_NAME, Model::DB_NAME, Model::ID_COLUMN, Model::UnknownAttribute
Instance Attribute Summary
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Model
all, attr_array_to_hash, column, count, create, db, destroy, #destroy, exists?, find, generate_id, hash_to_key_vals, #initialize, normalize_value_for_db, #save, sql, #sql, table_name, #update, update, where
Constructor Details
This class inherits a constructor from Kwipper::Model
Class Method Details
.authenticate(username, password) ⇒ Object
7 8 9 10 |
# File 'app/models/user.rb', line 7 def self.authenticate(username, password) user = where(username: username).first user && user.hashed_password == password && user end |
Instance Method Details
#favorite?(post) ⇒ Boolean
12 13 14 15 |
# File 'app/models/user.rb', line 12 def favorite?(post) result = sql("SELECT COUNT(id) FROM post_favorites WHERE user_id = #{id} AND post_id = #{post.id} LIMIT 1").first result.first && result.first > 0 end |