mysql - How to store each record or row in descending order into database in rails? -
i want store record or row in descending order of scores of match database in ruby on rails. can top 3 topper rank of current user. don't know how this.
the problem simple: don't need specify order when insert data in database. database engine capable of sorting data according instructions when perform select.
simply create rails model store score
, reference of subject associated score (e.g. user_id).
then, solution selecting records ordering score. assuming model called result
result.order("score desc").limit(3)
just small note. simple problem, long have necessary basic knowledge of ruby, rails , database interaction.
this answer helpful if do. if don't, you'll need start simpler problems learn these topics first.
Comments
Post a Comment