So, I have an app with Users who have user profiles and I have a visitors tab that I'd like to show the user who has visited their profile.
How might I accomplish this? I have a user model at the moment, I'm guessing I'd need to use a HMT perhaps? I.e. A user has_many visitors through user_visitors or something.. Can you please clear up how this can be done?
You can create a join model, named
Visit
and User model:
To create visits, put your controller users_controller a before_action:
or, if you dont want repeated visits:
And vualá!
Now you can user something like this:
Or with some conditions:
you also can put conditions on you relation:
Hope it helped!