kimkunjj
kimkunjj

Reputation: 1006

Rails AR cannot update NULL datetime field

I am using Rails 3.1. I have a database column t.datetime "end_at". If I enter a date at the time of object creation, then I can change the value (update) later. But If I leave it blank (NULL), I found that I cannot update it. I verified that the name and new value of the field are in the params. Why?

 def update
   begin
     model = MyModel.find(params[:id])
     model.update_attributes!(params[:my_model])
   rescue ActiveRecord::RecordNotFound => e
      #something
   end
 end

Upvotes: 0

Views: 779

Answers (1)

Julik
Julik

Reputation: 7856

You need to make sure two things are true:

  • your params[:end_at] must contain a nil or a DateTime. Normally params do not come in as datetime.
  • your column should not be a TIMESTAMP (but this is probably not the case already)

Also investigate multiparameter attributes.

Upvotes: 1

Related Questions