# Nulling a nullable boolean value from the UI?

**URL:** <https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444>\
**Category:** Rails\
**Created:** [December 4, 2005, 7:26pm UTC](https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444 "2005-12-04T19:26:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [December 4, 2005, 7:26pm UTC](https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444/1 "2005-12-04T19:26:53Z")

</div>

In my model class I have a boolean attribute which can be NULL. I’d like  
to set all three possible values from the UI using radio buttons. These  
radio buttons have the values “true”, “false”, and “” respectively. The  
trouble is that Column#type\_cast casts “” to false. The only way to get  
a nil value out of #type\_cast, is to pass in nil. Of course, that’s not  
what I get in the request; there the closest thing to a nil is an empty  
string.

So, how are others handling this?

Michael

–  
Michael S. Face reality and stare it down  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) --Jethro Tull, Silver River Turning  
[Michael Schürig | Sentenced to making sense](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [December 5, 2005, 3:54pm UTC](https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444/2 "2005-12-05T15:54:42Z")

</div>

On 4-dec-2005, at 19:22, Michael S. wrote:

> not  
> what I get in the request; there the closest thing to a nil is an  
> empty  
> string.
> 
> So, how are others handling this?

I do it like this.

[http://julik.textdriven.com/svn/tools/rails\_plugins/attribute\_cleanup/](http://julik.textdriven.com/svn/tools/rails_plugins/attribute_cleanup/)  
init.rb

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [December 5, 2005, 7:40pm UTC](https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444/3 "2005-12-05T19:40:34Z")

</div>

On 5-dec-2005, at 17:03, Michael S. wrote:

> I considered something similar, but came down to this
> 
> [http://dev.rubyonrails.org/ticket/3102](http://dev.rubyonrails.org/ticket/3102)

I hope they accept it, it’s indeed more thorough. Can you add some  
tests to it?

–  
Julian ‘Julik’ Tarkhanov  
me at julik.nl

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [December 5, 2005, 5:04pm UTC](https://www.ruby-forum.com/t/nulling-a-nullable-boolean-value-from-the-ui/49444/4 "2005-12-05T17:04:19Z")

</div>

On Monday 05 December 2005 15:51, Julian ‘Julik’ Tarkhanov wrote:

> On 4-dec-2005, at 19:22, Michael S. wrote:  
> [snip]
> 
> > So, how are others handling this?
> 
> I do it like this.
> 
> [http://julik.textdriven.com/svn/tools/rails\_plugins/attribute\_cleanup](http://julik.textdriven.com/svn/tools/rails_plugins/attribute_cleanup)  
> / init.rb

I considered something similar, but came down to this

[http://dev.rubyonrails.org/ticket/3102](http://dev.rubyonrails.org/ticket/3102)

Michael

–  
Michael S. Life is what happens  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) While you’re making plans  
[Michael Schürig | Sentenced to making sense](http://www.schuerig.de/michael/) --Kevin Gilbert, A Long Day’s Life
