So that one has me a little confused, also it might be unjustified but I'd like some input regardless.

I've got a rails 3.1.3 application with customers who are able to view media files. I wish to keep past their activities with their media viewing. The aim would be to have the ability to record a brief history such will be able to track it in the user or in the media e.g. get data for user.history() and media.history() to exhibit both all the media utilized with a user and every one of the customers who utilized a specific bit of media, together with other data regarding each transaction.

To date the only method I've been in a position to develop that reasonably satisfies this really is to produce a single history object for every transaction, kind of such as this:

class history_item
   belongs_to: media_object
   belongs_to: user
   (other transaction-specific data)
end

What concerns me about this is actually the quantity of database records will rapidly skyrocket using the typical utilization of this application. It is possible to better method to approach this issue which i haven't considered? I'm a new comer to rails and enormous web database integration generally, and I am unsure of about how exactly this kind of factor is generally done.

I'd create this type of model like a Viewing class like a HABTM model between User and MediaObject. This will make the particular structure more apparent than simply getting a relation known as history. You are able to obviously add techniques for User#history and MediaObject#history too, if you would like that exact interface that you simply referred to.

class User
  has_many :viewings
  has_many :viewed_media_objects, :through => :viewings
end

class MediaObject
  has_many :viewings
  has_many :viewers, :through => :viewings
end

class Viewing
  belongs_to :user
  belongs_to :media_object
end

When querying these objects, for instance given a user = User.first, knowing that you would like to iterate within the user's viewed_media_objects within an action, you could utilize @user = User.include(:viewed_media_objects).find(params[:id]) to make certain rails brings the attached viewings and media objects simultaneously because the user. By doing this, you will not get a lot of database calls.