Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding attribute to rails model object
    primarykey
    data
    text
    <p>I have a model <strong>students</strong>. in <em>studentsController</em> I select a collection of students. I want to attach a flag to the first and the last record. </p> <p>I'll display the list of students with a partial like this: <strong>students/_student</strong> and when a user clicks each student, they'll get a popup. </p> <p>I want to use the flag to determine whether this student is the first/last so that I can add a query parameter to the url. So for instance, the url will look like this when you hover over the first student: <strong>localhost:3000/student/1?location=first</strong></p> <p>When displaying though a partial, the collection is not present in the partial, and so I cannot just do a test like this: student.first?</p> <p>Any ideas? Thank you.</p> <p>[EDIT]. This was originally a reply to @neils, but I figured I'd put it out there: It works however I have another issue. Because I'm using an "auto-scroll" feature, which loads in more students as the user scrolls down the page ( 3 at a time), the "first" and "last" gets added to the first and third student of each row rather than the actual first and last of the collection. The way I do the auto-scroll: I use $.getScript to request the <strong>index.js.erb</strong> file. That file renders the <strong>students/_student</strong> like so: <em>render @students</em>, and attach to a container div. I render the url in that template (<strong>students/_student</strong>), so the params gets rendered every first/third time.</p>
    singulars
    1. This table or related slice is empty.
    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. 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