Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like it should be:</p> <pre><code>#GET /students/{:id} def show @student = Student.find_by_url(params[:id]) #BULLETS Randomizing /students/new.html.erb if cookies[:bullets].nil? @bullets = Bullet.all.shuffle.first(4) cookies[:bullets] = @bullets.collect(&amp;:id) else # simpler to use an 'in list' for only 4 id's Bullet.where("id in (?)", cookies[:bullets]) end respond_to do |format| format.html # show.html.erb format.json { render json: @student } end end </code></pre> <p>Notice I converted your loop over the <code>cookies</code> array into a single statement with an 'in list' -- that should simplify the sql generated for the lookups.</p> <p>Although, it's arguable that this code should be pushed into the model:</p> <pre><code>class Bullet &lt; ActiveRecord::Base NUM_USER_BULLETS = 4 # fetch a random set of def self.user_bullets Bullet.all.shuffle.first(NUM_USER_BULLETS) end end </code></pre> <p>Or something similar. Then your controller is simpler:</p> <pre><code>#GET /students/{:id} def show @student = Student.find_by_url(params[:id]) #BULLETS Randomizing /students/new.html.erb if cookies[:bullets].nil? @bullets = Bullet.user_bullets cookies[:bullets] = @bullets.collect(&amp;:id) else # simpler to use an 'in list' for only 4 id's Bullet.where("id in (?)", cookies[:bullets]) end respond_to do |format| format.html # show.html.erb format.json { render json: @student } end end </code></pre> <p>With the code migrated into your model, your controller is simpler.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload