尝试使用名为“buy-only”的键为 Document 设置 MongoMapper 对象。当我尝试启动应用程序时,我得到了这个
(eval):1: syntax error, unexpected '-', expecting ';' or '\n'
def buy-only ^
(eval):3: syntax error, unexpected keyword_end, expecting end-of-input
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/keys.rb:88:in `module_eval'
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/keys.rb:88:in `create_accessors_for'
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/keys.rb:27:in `block in key'
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/keys.rb:25:in `tap'
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/keys.rb:25:in `key'
.rvm/gems/ruby-2.0.0-p0/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/protected.rb:20:in `key'
这是我对模型中键的定义:
key :'buy-only', Boolean,
似乎 MongoMapper 正在尝试自动生成一个函数来处理仅购买的密钥,并且由于连字符不是有效的语法,所以它失败了。这个错误有什么解决方法吗?请不要质疑 Mongo 属性名称中连字符的使用。如果我能改变这一点,我就不会问了。