Merging data from multiple Rails tables in a view
<p>I am making a game in Rails where there are multiple games each day at different times. In my Pages Controller, I am showing users what the next four available games are: </p>

<pre><code>  @quizzes = Quiz.where("game_start &gt;= ?", Time.now).order(game_start: :asc).limit(4)
</code></pre>

<p>The <code>Quiz</code> model has a <code>game_start</code> column, so this is easy. </p>

<p>I would like to have a second table for the user showing what the next games are that <em>they have registered for</em>. So this will need to be specific to the <code>current_user</code>, and it will need to check a <code>Reservation</code> table used to indicate if a user has already registered for the game. </p>

<p>This is where it gets tricky. Based on the best practice to use specific, smaller models, the table for <code>Reservation</code> is the following: </p>

<pre><code> class CreateReservations &lt; ActiveRecord::Migration
   def change
     create_table :reservations do |t|
       t.integer :user_id
       t.string :category
  t.timestamps
  end
 end
end
</code></pre>

<p>So in my controller, if I were to use: </p>

<pre><code> @reservations = Reservation.where(user_id: current_user.id)
</code></pre>

<p>It will return the <code>category</code> name of games a user has registered for. This isn't very useful to the user though. Information like <code>game_start</code> (when a game begins) is located in the <code>Quiz</code> model, referenced above. </p>

<p>Let's say I format this in the view as a table. One column is using <code>@reservations</code> to query which <code>category</code> games have been signed up for (like "history" and "sports"). Could I also query the <code>@quizzes</code> model to - in the table table - show corresponding <code>game_start</code> times? </p>

<p>In short, I want the controller to 1) show the user the games they have signed up for (working) and 2) based on the <code>category</code> of those games, query the <code>Quiz</code> table and also show the <code>game_start</code> times. </p>

<p>Is that possible? </p>

<p>Additional, For Reference: <code>Quiz</code> Table: </p>

<pre><code>class CreateQuizzes &lt; ActiveRecord::Migration
  def change
    create_table :quizzes do |t|
      t.string :category
      t.datetime :game_start
      t.integer :entry
      t.timestamps
    end
</code></pre>