0

使用在乘客和 ruby​​ 1.8 上运行的数据映射器在字段上声明必需时,我的 sinatra 应用程序显示错误

错误:Person:Class 的未定义局部变量或方法“必需”

class Person
include DataMapper::Resource
property :id, Serial
property :salutation, String 
property :first_name, String , required => true 
property :last_name, String , required => true 
property :email, String , required => true, :format => :email_address 
property :phone, String , required => true
property :dob, String 
property :no_of_guests, String , required => true
property :attending, String, required => true

property :created_at, DateTime
end

这是 datamapper 和 ruby​​ 1.8 的问题,还是乘客的问题,还是我标记所需属性的方式?

4

1 回答 1

0

required必须是符号 ( :required):

class Person
include DataMapper::Resource
property :id, Serial
property :salutation, String 
property :first_name, String , :required => true 
property :last_name, String , :required => true 
property :email, String , :required => true, :format => :email_address 
property :phone, String , :required => true
property :dob, String 
property :no_of_guests, String , :required => true
property :attending, String, :required => true

property :created_at, DateTime
end
于 2012-10-02T10:58:06.287 回答