Sent from my iPhone
On Mar 3, 2010, at 8:00 PM, dare ruby
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
> 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?
# do something for the true case
else
# 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
> 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
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-
> talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> .
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
> .
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.