0

My sinatra app is showing an error when declaring required on fields using datamapper running on passenger and ruby 1.8

error: undefined local variable or method `required' for 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

Is this an issue with datamapper and ruby 1.8, or passenger or the way I'm decalring the required attribute?

Will
  • 4,498
  • 2
  • 38
  • 65

1 Answers1

0

requiredhas to be a symbol (: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
three
  • 8,262
  • 3
  • 35
  • 39
  • oh dear. Thank you. i also got round it doing this: validates_presence_of :email, :last_name, :phone etc – Will Oct 02 '12 at 11:19
  • it is a common mistake and it can take hours to figure that out if you're not used to that. Use the #datamapper channel on freenode to get faster answers. – three Oct 02 '12 at 15:36