Hi everyone again.
I’m trying to develop a database and tables which have the association
Video 1 ----- 0…n Script
So, in ‘script.rb’
class Script < ActiveRecord::Base
and in ‘video.rb’
class Video < ActiveRecord::Base
Furthermore, in order to refer to the parent (in this case, ‘Video’), I
need to set video_id:integer for Script. Am I correct ?
in the migration file,
class CreateScripts < ActiveRecord::Migration
create_table :scripts do |t| t.references :video t.string :text ... end add_index :scripts, :video_id
My question is: how can I actually associate a new ‘script’ entry with
its parent, ‘video’, in making a new ‘Script’ entry ?
For example, in ‘index.html.erb’ for NewScript page, I tried to put
<td><%= script.video_id %></td>
and in script_controller.rb
@script.video = Video.where(:video_id)
But certainly does not seem to work at all.
Could anyone show me how to set up ‘html.erb’ and ‘controller.rb’ to
associate a new ‘Script’ entry with its parent specifically ?
Thanks in advance.