0
alex@alex-ThinkPad-T410:~/rails_projects/final$ rake db:migrate
rake aborted!
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:3: syntax error, unexpected ':', expecting ';' or '\n'
    add_column :microposts, :price, :text # d...
                ^
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:3: syntax error, unexpected ',', expecting tCOLON2 or '[' or '.'
...add_column :microposts, :price, :text # dont forget to chang...
...                               ^
/home/alex/rails_projects/final/db/migrate/20120813025503_add_price_location_and_product_to_microposts.rb:7: syntax error, unexpected keyword_end, expecting $end

それがエラーです。これが移行です(以下)

class AddPriceLocationAndProductToMicroposts < ActiveRecord::Migration
  def 
    add_column :microposts, :price, :text 
    add_column :microposts, :location, :text
    add_column :microposts, :product, :text
  end
end

これを念頭に置いて書きましたhttp://guides.rubyonrails.org/migrations.html#changeing-migrationsセクト. 2.2

なぜセミコロンが必要なのですか?価格、場所、製品の列をマイクロポスト テーブルに追加しようとしています。

4

1 に答える 1

2

の前にメソッド名を書く必要がありますdef

すなわちdefに変更def change

class AddPriceLocationAndProductToMicroposts < ActiveRecord::Migration
  def change
    add_column :microposts, :price, :text 
    add_column :microposts, :location, :text
    add_column :microposts, :product, :text
  end
end
于 2012-08-13T05:17:19.587 に答える