ruby on rails - Checking whether a user has interacted with an item -


I have a table for users and items, whatever I would like is a way to get all the items that are special The user has not yet completed How would I go about it efficiently in an idiomatic rail? I was thinking of creating a new table called Usurites, which contains a user_id and item_id column. I think this is the right approach, but I'm not sure how I would actually get the user's incomplete items. What is the right activation syntax?

Thank you!

@

strong>

If you have a model included, you can only UserItem s, which is interacted / completed with the user (for efficiency). To complete the items, I will compare items that have been completed from the list of items:

  # app / model / user.rb class user & lt; ActiveRecord :: Base has has_many: user_items has_many: items, via: user_items def, incomplete_times target = self.items return items. All.where ('id! =?', Target) end #user_items id | User_id | Item_ID | Made_at | Updated_at   

To get a list of items not included in your user_items @user = User.incomplete_items Will allow. > Add to Model

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -