将表添加到datamapper会给出“未初始化的常量”错误

时间:2013-05-15 13:41:49

标签: ruby sinatra datamapper

我正在尝试向我的应用添加一个表,但是当我这样做时,我会收到如下所示的错误。但我不明白为什么?我所做的只是添加推荐类。

class Item
  include DataMapper::Resource
  property :id, Serial
  property :sortorder, Integer
  property :title, Text
  property :company, String
  property :desc, Text
  property :year, Integer
  property :url, String
  mount_uploader :source, ImageUploader
end

class Recommendations
  include Datamapper::Resource
  property :id, Serial
  property :firstname, String
  property :lastname, String
  property :title, String
  property :mugshot, String
  property :text, Text
end

configure :development do
    DataMapper.auto_upgrade!
    DataMapper.finalize
    puts "you're developing"
end 

错误:

15:30:27 [rerun] Joelsanden-se launched

/Users/simpel/Sites/ruby/joelsanden-se/main.rb:48:in `<class:Recommendations>': uninitialized constant Recommendations::Datamapper (NameError)
from /Users/simpel/Sites/ruby/joelsanden-se/main.rb:47:in `<top (required)>'
from /Users/simpel/Sites/ruby/joelsanden-se/config.ru:19:in `require'
from /Users/simpel/Sites/ruby/joelsanden-se/config.ru:19:in `block in <main>'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/simpel/Sites/ruby/joelsanden-se/config.ru:in `new'
from /Users/simpel/Sites/ruby/joelsanden-se/config.ru:in `<main>'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/bin/rackup:23:in `load'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/bin/rackup:23:in `<main>'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/simpel/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'

15:30:29 [rerun] Joelsanden-se Launch Failed

1 个答案:

答案 0 :(得分:3)

你有一个拼写错误 - Datamapper DataMapper

所以使用

include DataMapper::Resource

而不是

include Datamapper::Resource