我有两个模型,如下所示。的一个实例Share
可能有多个 的实例Color
。我正在使用 MongoMapper 来管理这些模型。当我这样做时Share.create
,我收到以下错误:
NameError:未初始化的常量颜色
谁能告诉我这是为什么?
/models/share.rb:
class Share
include MongoMapper::Document
key :shorten_id, String
key :name, String
many :colors, :class_name => "Color"
timestamps!
end
/models/color.rb:
class Color
include MongoMapper::Document
key :celcius, Float
key :hue, Float
key :saturation, Float
key :brightness, Float
belongs_to :share, :class_name => "Share"
timestamps!
end
这是我尝试创建实例的地方:
/routes/api.rb:
require 'json'
class App < Sinatra::Base
register Sinatra::Namespace
namespace '/api' do
before do
protected!
end
get '/shares' do
content_type 'application/json'
Share.all.to_json
end
post '/share' do
@share = Share.create
@share.save
end
end
end