1.use has_one create connection with page on subject
#vim app/models/subject.rb
add new line in it
has_one :page
2.use belongs_to create connection with subject on page
# vim app/models/page.rb
add new line in it
belongs_to :subject
3.use console create connection on subject with page
#rails console
first_page = Page.new(:name=>"first page",:permalink=>"first",:position=>1)
first_page.save
second_page = Page.new(:name=>"second page",:permalink=>"second",:position=>1)
second_page.save
4.use subject to get id 2 on Subject
subject = Subject.find_by_id(2)
subject.page = second_page
沒有留言:
張貼留言