저는 Rails 3 in Action을 읽고 축 어적 명령을 따르고 있습니다. 왜 클래스 메소드가 있으며ActiveRecord :: Migration의 서브 클래스로 메소드를 위아래로 생성하지 않는 이유는 무엇입니까?
class CreatePurchases < ActiveRecord::Migration
def change
create_table :purchases do |t|
t.string :name
t.float :cost
t.timestamps
end
end
end
: 내가 대신이 코드를 얻을
class CreatePurchases < ActiveRecord::Migration
def self.up #not created in my code
create_table :purchases do |t|
t.string :name
t.float :cost
t.timestamps
end
end
def self.down # not created in my code
drop_table :purchases
end
end
: 나는 명령을 실행할 때,
는rails new things_i_bought
cd things_i_bought
bundle install
rails generate scaffold purchase name:string cost:float
이 책은이 코드를 받아야 말한다 나를 위해 창조되지 않은가? 나는 레일 3.1.1과 루비 1.9.2를 사용하고 있습니다.
굉장해! 고마워요. – lampShade
이 사이트는 사람이 굉장합니다. 질문을하고, 15 분 이내에 * 당신이 물어 본 책의 저자 *로부터 답을 얻으십시오. +1 –