How do I store arrays values in the database using ruby on rails? I am building a school timetable which have 6 periods a day. I am storing the subject ID into an array, but I just don't know how to save the id values of that array.
My Controller:
def create
@timetable = Timetable.new(params[:timetable])
@buildtimetable = params[:gradeclassroomsubject_id]
@buildtimetable.each do |subjectID|
subjectID.save!(params[:gradeclassroomsubject_id].reject { |k,v| v.blank? })
end
end
class CreateTimetables < ActiveRecord::Migration
def change
create_table :timetables do |t|
t.integer :period_no
t.integer :day_no
t.integer :gradeclassroomsubject_id
t.integer :user_id
t.timestamps
end
end
end
Any help is much appreciated I am way under pressure and this kinda feels embarrassing.
Many thanks
timetable, and there is another model calledsubject. You want to create a relationship between this two tables. Is my understanding right?timetablehas 7 days, each of which has 6 periods, and you want to link subject_id to each period? or eachtimetableis a day?