# Boolean column problem

**URL:** <https://www.ruby-forum.com/t/boolean-column-problem/129590>\
**Category:** Rails\
**Created:** [February 19, 2008, 10:42pm UTC](https://www.ruby-forum.com/t/boolean-column-problem/129590 "2008-02-19T22:42:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@Robin\_F](https://www.ruby-forum.com/u/Robin_F)\
**Post date:** [February 19, 2008, 10:42pm UTC](https://www.ruby-forum.com/t/boolean-column-problem/129590/1 "2008-02-19T22:42:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robin\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@Robin\_F](https://www.ruby-forum.com/u/Robin_F)\
**Post date:** [February 20, 2008, 2:09am UTC](https://www.ruby-forum.com/t/boolean-column-problem/129590/2 "2008-02-20T02:09:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robin\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@Robin\_F](https://www.ruby-forum.com/u/Robin_F)\
**Post date:** [February 20, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/boolean-column-problem/129590/3 "2008-02-20T19:52:21Z")

</div>

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.
