现在的位置: 首页 > 综合 > 正文

创建数据方法

2013年04月17日 ⁄ 综合 ⁄ 共 584字 ⁄ 字号 评论关闭

class Student < ActiveRecord::Base
    def initialize ( stu_num, name, department )
      initialize
      end
  end
 
s1 = Student.new
s1. stu_num = "00000001"
s1.name = "first"
s1.department = "computer"
s1.save

Student.new do | s2|
  s2.stu_num = "00000002"
  s2.name = "two"
  s2.department = "home"
  s2.save
end
 
 s3 = Student.new(
  :stu_num => "000000003",
  :name => "three",
  :department => "town"
 )
 s3.save
 
 s4 = Student.create(
  :stu_num => "000000004",
  :name => "four",
  :department => "country"
 )
 
 s5 = Student.create(
[{
  :stu_num => "000000005",
  :name => "five",
  :department => "china"
},{
   :stu_num => "000000006",
  :name => "six",
  :department => "English"

}

])
 

抱歉!评论已关闭.