Ruby DataMapper保存失败,但没有错误
当我尝试使用DataMapper修改然后保存模型时,我得到了一个SaveFailure异常,但没有错误 具体地说,我看到这条信息: “MonthlyBill#save返回false,MonthlyBill未保存” 这是执行保存操作的代码:Ruby DataMapper保存失败,但没有错误,ruby,sinatra,datamapper,Ruby,Sinatra,Datamapper,当我尝试使用DataMapper修改然后保存模型时,我得到了一个SaveFailure异常,但没有错误 具体地说,我看到这条信息: “MonthlyBill#save返回false,MonthlyBill未保存” 这是执行保存操作的代码: post '/monthly_bills' do with_authenticated_user do |user| description = params[:description] expected_amount = params[:expe
post '/monthly_bills' do
with_authenticated_user do |user|
description = params[:description]
expected_amount = params[:expected_amount]
pay_period = params[:pay_period]
monthly_bill = MonthlyBill.new(:description=>description, :expected_amount=>expected_amount, :pay_period=>pay_period)
user.monthly_bills << monthly_bill
user.save
end
月度票据模型:
class MonthlyBill
include DataMapper::Resource
property :id, Serial
property :description, String
property :expected_amount,Decimal
property :pay_period, Integer
belongs_to :user
end
问题是什么?更重要的是,我如何让DataMapper更具体地告诉我问题出在哪里?嗯-那些大写的属性看起来让我担心。我会
has n, :monthly_bills
has 1, :current_pay_period #do you really have a CurrentPayPeriod model?!
然后尝试:
monthly_bill = MonthlyBill.new(:description=>description,:expected_amount=>expected_amount, :pay_period=>pay_period, :user=>user)
monthly_bill.save
嗯,那些资本化的房产看起来让我担心。我会
has n, :monthly_bills
has 1, :current_pay_period #do you really have a CurrentPayPeriod model?!
然后尝试:
monthly_bill = MonthlyBill.new(:description=>description,:expected_amount=>expected_amount, :pay_period=>pay_period, :user=>user)
monthly_bill.save
哈哈,我真的。。。在我的问题域中没有一种程序化的方法来检测支付期…而且我做了你建议的更改,我仍然有相同的错误。然而,我确实让我的月班资本化了。可以吗?STDERR.puts月度账单。错误。除非月度账单有效,否则检查?你是否删除了user.monthly\u bills我忽略了尝试monthly\u bill.save所以现在我得到了我的错误。。。修正了一个和另一个是关于一些属性没有被设置时,它甚至不存在于我的模型。。。谢谢你帮助我前进!:)哈哈,我真的。。。在我的问题域中没有一种程序化的方法来检测支付期…而且我做了你建议的更改,我仍然有相同的错误。然而,我确实让我的月班资本化了。可以吗?STDERR.puts月度账单。错误。除非月度账单有效,否则检查?你是否删除了user.monthly\u bills我忽略了尝试monthly\u bill.save所以现在我得到了我的错误。。。修正了一个和另一个是关于一些属性没有被设置时,它甚至不存在于我的模型。。。谢谢你帮助我前进!:)