class Books < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.column :title, :string, :limit => 32, :null => false
t.column :price, :float
t.column :subject_id, :integer
t.column :description, :text
t.column :created_at, :timestamp
end
end
def self.down
drop_table :books
end
end
create_table :books do |t|
这一句 没有迭代操作 为什么会有 ruby do |t|
这句呢 这里的 ruby do |t|
到底是什么意思? 求高人解答
不是迭代而是回调。
关于Ruby的回调:
http://stackoverflow.com/questions/1677861/how-to-implement-a-callback-in-ruby
关于Rails的Migration:
http://guides.rubyonrails.org/migrations.html
如果你用jQuery做过Ajax的话,应该有类似这样的经验:
$.get()
方法的返回值是test.php的response body,第一个参数是请求的url,第二个参数就是回调函数,这个函数接受test.php的response body作为参数data的值,并通过弹窗显示。这条Migration语句你可以这么理解。