I'm trying to make a simple room management service. The rooms have these properties:
class Room
include DataMapper::Resource
validates_is_unique :number
property :id, Serial
property :number, Integer
property :guest, String
property :status, Enum[ :free, :occupied ], :default => :free
end
Then I create a new room like this
post '/new' do
content_type :json
@room = Room.new :guest => params[:guest],
:number => params[:number],
:status => params[:status]
if @room.save
{ :number => @room.number, :guest => @room.guest, :status => @room.status }.to_json
end
end
through this haml form
%form#new_message{:action => '/new', :method => 'post'}
%p
%input{:type => "text", :id => "number", :name => "number"}
%input{:type => "text", :id => "guest", :name => "guest"}
%input{:type => "checkbox", :id => "status", :name => "status", :value => "occupied"}
%input{:type => "submit", :value => "post"}
When the box is checked the :status is "occupied" but when I leave it unchecked the object won't save. I thought it would work since it is defaulted to "free" but no...