我刚刚从实用程序员的敏捷Web开发与Rails的Ruby on Rails学习。在rails上的语法错误ruby
我已经写了一个小程序,它运行时,我收到下面的语法错误,当我运行它:
/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安装吗?
感谢马克,我应该知道!我已经改变了上述内容,现在我保存了文件,找不到表'产品' – user1900791
您的迁移很可能无法运行,或者您之前没有运行过。从你的终端尝试'rake db:migrate'。 –