控制器/ makenew.rb爲什麼Sequel不會寫我的數據庫表?
class MakeController < Controller
map '/makenew'
#require 'model/debate'
def debate
if request.post? #this line is potentially dangerous!
#---> 1/3 fetch postdata
data = request.subset(:question, :type, :category, :assertion)
data['user_id'] = user.id #id = request.params['id']
#---> 2/3 check permissions
if user.points < 40
flash[:error] = 'You don\'t have enough points to make a debate.'
redirect_referrer
else
debate = Debate.new
end
#---> 3/3 modify database
begin
debate.save(data)
flash[:success] = success
flash[:form_data] = debate
redirect 'debates'
rescue => e
Ramaze::Log.error(e)
#flash[:form_errors] = debate.errors
#flash[:error] = data
flash[:error] = e
#flash[:error] = 'Failure whilst saving. Contact technical support!'
redirect 'debates' #redirect_referrer
end
#|
end #closes posting conditional
end #closes makesave
end
我得到的錯誤是。
的SQLite3 :: ConstraintException:debates.question不能爲null
我已經檢查了POSTDATA爲data.question
,它不爲空。
這是怎麼回事?
[The doc](http://sequel.rubyforge.org/rdoc/files/doc/mass_assignment_rdoc.html)說:「在所有的質量分配情況下,以set開頭的方法將設置屬性而不保存對象,而以update開頭的方法將設置屬性**,然後將更改保存到對象**中。「 –