Following should be Model code:
Class Window < ActiveRecord::Base
has_many :channels
end
class Channel < ActiveRecord::Base
belongs_to :window
end
In the console, do the following:
@window = Window.create(window: "This is window-1")
This will create a windows-instance and saves it into the database.
100.times do |index|
Channel.create(channel: Random.rand(1000),
data: Random.rand(1000),
window: @window)
end
This will create 100 Channel instances that belong to the earlier-created-window. Also, saves them to the database.
@window.channels
will return the corresponding 100 channels.
This is how you write/insert record and read/fetch record.
Please do read http://edgeguides.rubyonrails.org/active_record_basics.html#create and http://edgeguides.rubyonrails.org/active_record_basics.html#read for better clarity and exploring futher,