View and Submit entries in batches/slots

10 views
Skip to first unread message

Aditi Thakur

unread,
Sep 2, 2015, 12:36:32 PM9/2/15
to Ruby on Rails: Talk

I am designing a rails application in which there is model named race_timing which store the timings of students participate in different events.On view page names of student according to selected event and age group is displayed for entering the time taken by each individual to complete the race.Currently I am storing the student_id and their corresponding timing in an array as I want to submit multiple entries on single submit and it is working properly. But now I want to display only 8 students at a time from the array and store their corresponding timings but i am not getting a proper way to do so. Can anyone suggest some solution??

Colin Law

unread,
Sep 2, 2015, 2:14:02 PM9/2/15
to Ruby on Rails: Talk
Whenever you find yourself storing an array you are almost certainly
doing it wrong.

I suggest
Student
has_many race_timings

RaceTiming
belongs_to Student
belongs_to Race

Race
has_many race_timings

Each race_timing record contains student_id, race_id and timing data
You can also say
Student has_many races through race_timing
and
Race has_many students through race_timing
if those would be useful

If you have a race in @race for example, the timings for the race are
@race.race_timings and the students are @race.students, and for any
given timing you can say race_timing.race or race_timing.student.

There is no reason that you cannot create multiple timings records in
one submit, which I suggest would be to the race controller, as you
are submitting timings for the race.

Colin
Reply all
Reply to author
Forward
0 new messages