# How to assign boolean values?

**URL:** <https://discuss.rubyonrails.org/t/how-to-assign-boolean-values/49863>\
**Category:** rubyonrails-talk\
**Created:** [March 4, 2010, 4:00am UTC](https://discuss.rubyonrails.org/t/how-to-assign-boolean-values/49863 "2010-03-04T04:00:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 4, 2010, 4:00am UTC](https://discuss.rubyonrails.org/t/how-to-assign-boolean-values/49863/1 "2010-03-04T04:00:45Z")

</div>

Dear Friends,

I have created a Boolean field like

table.boolean :log\_status, :default =\> 0, :null =\> false

When i try to add log\_status in my controller part, by default the value is assigned as 1.

I dont know why it is?

I aslo assigned the value as zero explicitly, like

@log = LogSettings.new @log.log\_status = 0

but even after hard coding like this, the log\_status field is added as 1 only.

could any anyone please suggest on why its so?

In mysql the field is created as

Field Datatype Null Default 'log\_status', 'tinyint(1)', 'NO', '', '0', ''

Thanks in advance

Regards, Martin

---

<div class="post-metadata">

**Author:** ![Con](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Con](https://discuss.rubyonrails.org/u/Con)\
**Post date:** [March 4, 2010, 4:58am UTC](https://discuss.rubyonrails.org/t/how-to-assign-boolean-values/49863/2 "2010-03-04T04:58:03Z")

</div>

> Dear Friends,
> 
> I have created a Boolean field like
> 
> table.boolean :log\_status, :default =\> 0, :null =\> false

Hi, the above could have been easily implemented as follows:

table.boolean :log\_status, :default =\> false, :null =\> false

> When i try to add log\_status in my controller part, by default the value is assigned as 1.
> 
> I dont know why it is?

> I aslo assigned the value as zero explicitly, like
> 
> @log = LogSettings.new @log.log\_status = 0

I would recommend using true and false within your Ruby code because 0 is interpreted as a true value condition. Also, when you access the column within your Ruby code, the following is recommended approach:

if @log.log\_status? &nbsp;&nbsp;&nbsp;# do something for the true case else &nbsp;&nbsp;&nbsp;# do something for the false case end

Note: you'll need to append the '?' onto boolean column's name when accessing it within your code.

Good luck,

-Conrad
