I have an issue and I'm trying to figure out the best/simplest way to resolve this...
I have multiple users on my app. the app allows users to add books to a read-queue list (like a list of books a user can keep tabs on).
Originally, I set the read-queue list as a global array. However this meant that multiple users were adding books to a single global array. If user1 added 3 books, user2 would also see those 3 books. Or if user1 cleared the read-queue list, user2's books were cleared too.
Possible Solutions:
Maybe I can create a key in the array to associate a portion of it to a user, but I imagine that the array would get pretty large...
Maybe create a db table "queue-list".. but that seems like a lot to do for something like this..
Maybe create a global array unique for each user. (I like this one, but not sure how to do that)
Hope this is clear, I'm pretty new to rails so any help is appreciated!
my attempt at solution 3:
books_controller.rb
def add_book_to_queue
user = User.find(params[:id])
user.read_queuelist.push(params[:book_info])
@readlist = user.read_queuelist
end
user.rb
def read_queuelist
$read_queuelist ||= Array.new
end
view
<%= @readlist %>