ruby - How can I find a puzzle the user has not yet solved in my Rails 4 app -


I am creating a simple puzzle game to track the tracks. 4. There are two models in my train app, users and puzzles. I am trying to understand how to design two models so that I can track a puzzle that the user has solved and to play it An unresolved puzzle can be found. The puzzle does not have to be solved in any order, so my app should be able to find any puzzle that the user has not yet solved.

There is a clear way to create multiple relationships between users and puzzles and create an attribute on the user model so that it can store the ID of the already resolved puzzle, then a simple DB Use a query that does not have a puzzle ID in the list, but it seems ineligible ...

  #Untested code, typos / bugs Sorry for the class user; ActiveRecord :: Base has_and_belongs_to_many: solved_puzzles, class_name: "puzzle" def unsolved_puzzle solved_puzzle_ids = self.solved_puzzles.map {| P | P.id} unsolved_puzzle = self.puzzles.where ("id not in?", Solved_puzzle_ids). First end and class puzzles & lt; ActiveRecord :: Base has_and_belongs_to_many: solved_by, class_name: "user" end   

Is there a problem with this approach? Other Thoughts?

Thanks in advance for your intelligence!

If you have__and_blog_to_you can only store links between user and puzzle I like I_many : Through the Association, where you can save the status of the puzzle for that specific user. The relationship between a user and a puzzle is now a separate class with the solution state. (Unchecked code)

  The class user has: user_puzzles is_maya: Puzzles, via: user_puzzles def unsolved_puzzle user_puzzles.where (Solved: incorrect). First End End Category UserPuzzle belongs_to: User belongs_to: puzzle #h attribute is the hotword and class puzzle. MMS: User_boxes near_mai: user, user_poxes and    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -