-1

我正在尝试向我的应用程序添加一个表格,但是当我这样做时,我得到了如下所示的错误。但我不明白为什么?我所做的只是添加了 Recommendation 类。

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
4

1 回答 1

3

你有一个错字 -Datamapper应该是DataMapper

所以用

include DataMapper::Resource

代替

include Datamapper::Resource
于 2013-05-15T14:29:40.623 回答