0

実用的なプログラマー「Agile Web Development with Rails」から Ruby on Rails を学び始めたばかりです。

小さなアプリケーションを作成しましたが、実行すると次の構文エラーが発生します。

/Users/colinlabri/Desktop/depot/app/models/product.rb:2: syntax error, unexpected ':',   expecting keyword_end
  attr_accessible : title, :description, :image_url, :price
                   ^
/Users/colinlabri/Desktop/depot/app/models/product.rb:2: syntax error, unexpected ',', expecting tCOLON2 or '[' or '.'
  attr_accessible : title, :description, :image_url, :price
                                        ^
 Rails.root: /Users/colinlabri/Desktop/depot

Application Trace | Framework Trace | Full Trace

app/controllers/products_controller.rb:1:in `<top (required)>'

DB のコードは次のとおりです。

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string : title
      t.text :description
      t.string :image_url
      t.decimal :price, precision: 8, scale: 2

      t.timestamps
    end
  end
end

バージョンは次のとおりです。 ruby​​ 1.9.3p362 Rails 3.2.11

sqlite のインストールを確認する必要がありますか?

4

2 に答える 2

1

この行を修正するだけです:

t.string : title

に:

t.string :title

モデルにもattr_accessible呼び出しで同じ問題があります。

于 2013-01-21T22:47:33.227 に答える
0

:somethingは実際には Ruby のシンボルです。:とシンボル名の間にスペースを入れることはできません。

移行ファイルの に変更t.string : titleします。t.string :title

製品モデルでは、

attr_accessible : titleに変更attr_accessible :title

于 2013-01-21T22:47:45.953 に答える