2

I am developing a social network for a class we have to be able to follow other user accounts. Right now I am stumped on whats the best way to do this I have a method follow that uses to user objects current_user.follow(user) something like that. How would I go about storing the information on the user index page so the current user could follow any of those users on that page.

Would it be best to store the user ids in an hidden field, and query for that user when the follow button is clicked.

tadman
  • 208,517
  • 23
  • 234
  • 262
Jack
  • 21
  • 1
  • Why not `current_user.following << user` where `following` is a relationship you've established as a `has_many ... :through` type structure? – tadman Nov 09 '16 at 20:02
  • I am using the act_as_follower gem to try to spped up development on the easy part to spend more time with the NEO4j side. – Jack Nov 09 '16 at 20:04
  • Then what does it recommend you do? – tadman Nov 09 '16 at 20:08
  • 1
    maybe you should look into the basics of Rails CRUD / REST before trying to use a non-standard data base – max pleaner Nov 09 '16 at 20:09
  • It is _never_ better to store sensitive information in a hidden field, especially when that information could grow in size. "hidden" only means it's not displayed by the browser in the rendered page, it doesn't mean it's hidden if someone looks at the source. – the Tin Man Nov 09 '16 at 22:51

1 Answers1

2

I've done this before - I always used a new model that representing the relationship eg

class Follow < ActiveRecord::Base
  # obviously, fix these to suit your preferred terminology
  # and include all the correct details
  has_one :follower, class_name: 'User'
  has_one :followee, class_name: 'User'
end

That way you can store related information - such as when the user followed the other user and it doesn't become ponderous when your users have follow-lists in the hundreds (if not thousands).

Then the views can implement some fairly standard patterns using rails resources.

As to implementing the views the way you say... I'm not sure what you're trying to describe. Can you show us the code you've already tried (even if it isn't working)? It'll give us a clearer picture of what you're trying to do.

max pleaner
  • 26,189
  • 9
  • 66
  • 118
Taryn East
  • 27,486
  • 9
  • 86
  • 108