Boolean column problem

Hi All,

As part of a wider application, I have a todo list set up with boolean
column indicating if the todo is complete or not. It defaults to
false to indicate not complete.

I’m using a check box that calls a defined action called
complete_item. At the moment it looks like this:

class TodosController < ApplicationController

def complete_item
@todo = @matter.todos.find_by_id(params[:id])
@todo.complete = true
@todo.save

end

I have also tried the following various methods, none of which work:

@todo.update_attributes(:complete, true)
@todo.attributes(:complete)=true
@todo.complete=true

I’ve also tried replacing true with 1.

I can see from the logs that the object is being updated but with the
complete field still set to false. Any thoughts?

Thanks

Robin

can you give more details like, what database are you using. MySql,
sqlite ?? what does your Todo model class look like? callbacks?
validations?

My sense is that maximilianog is on the right track. Often when
debugging an issue like this I’ll add something like this:

@todo.errors.each{|attr, errs| logger.debug “#{attr.to_s.humanize}
#{errs.to_s}” } unless @todo.valid?

The log messages (or their absence) will help you understand if your
failure to update is related to validations.

How are you defaulting complete to false? Is it the default value
(db) or via code?

@todo.update_attributes(:complete, true)
^ This one doesn’t work because update_attributes (plural) takes a
hash. Make it singular (update_attribute) and you might have success.