I’m just learning Ruby on Rails and ran into something where I know I’m
either doing something very stupid or I’m missing something.
My model as a boolean attribute called active_flag. In my Sql Server
database this is stored as a bit value. I then setup a method in my
controller called “deactivate”. This is very simple, it does:
On Thu, 2006-07-06 at 03:30 +0200, Mike Witt wrote:
It’s numeric (SQL Server’s bit type).
if it’s a numeric type, then it would seem that the only way to handle
it is to save/search for 0/1
Craig
Then I’m wondering why the scaffolding handles updates and inserts of
this without a problem. I thought of making this column a numeric type
and then wrapping it with a boolean accessor, but I’m guessing there is
a way to make it work with the boolean attribute.
You see, in my scenario, I’m just modifying the scaffold’s destroy
action to be a deactivate action. Since the update action can handle
this, I think I should be able to make the deactivate action handle it
as well.
On Thu, 2006-07-06 at 03:55 +0200, Mike Witt wrote:
this without a problem. I thought of making this column a numeric type
and then wrapping it with a boolean accessor, but I’m guessing there is
a way to make it work with the boolean attribute.
You see, in my scenario, I’m just modifying the scaffold’s destroy
action to be a deactivate action. Since the update action can handle
this, I think I should be able to make the deactivate action handle it
as well.
I’ve lost track of the issue and I don’t use the forum so I don’t
remember the context of the question.
On Thu, 2006-07-06 at 03:55 +0200, Mike Witt wrote:
this without a problem. I thought of making this column a numeric type
and then wrapping it with a boolean accessor, but I’m guessing there is
a way to make it work with the boolean attribute.
You see, in my scenario, I’m just modifying the scaffold’s destroy
action to be a deactivate action. Since the update action can handle
this, I think I should be able to make the deactivate action handle it
as well.
I’ve lost track of the issue and I don’t use the forum so I don’t
remember the context of the question.
You may want to repeat it.
Craig
The original issue:
Hi,
I’m just learning Ruby on Rails and ran into something where I know I’m
either doing something very stupid or I’m missing something.
My model as a boolean attribute called active_flag. In my Sql Server
database this is stored as a bit value. I then setup a method in my
controller called “deactivate”. This is very simple, it does:
Then I’m wondering why the scaffolding handles updates and inserts of
this without a problem. I thought of making this column a numeric type
and then wrapping it with a boolean accessor, but I’m guessing there is
a way to make it work with the boolean attribute.
I take this back … scaffolding does not handle the update. I think
the insert is only handled because I have a default value on the column.
and look at the session variables when you get the error to see what
value is in @department.active_flag
Craig
Sounds like a logic error in your validations, false is a weird bugger
in ruby so you have to be very careful about it. Try looking at the
validations you have and look for places where you’re using x == false
and try x === false or some variation of that.
IIRC, in ruby false is only false when it is the number 0 or the
constant false, so it could be something like the database
misunderstanding and deleting the value or something obscure like
that.
In addition to craigs idea you might try running the breakpointer
right before the save! and just looking at the values as well as
trying to change the var and save manually. Breakpointer rocks
mightily.
and look at the session variables when you get the error to see what
value is in @department.active_flag
Craig
Sounds like a logic error in your validations, false is a weird bugger
in ruby so you have to be very careful about it. Try looking at the
validations you have and look for places where you’re using x == false
and try x === false or some variation of that.
IIRC, in ruby false is only false when it is the number 0 or the
constant false, so it could be something like the database
misunderstanding and deleting the value or something obscure like
that.
In addition to craigs idea you might try running the breakpointer
right before the save! and just looking at the values as well as
trying to change the var and save manually. Breakpointer rocks
mightily.
Cheers,
Chuck V.
I’ve used the logger multiple times examining the active_flag attribute
and I’m pretty sure it really is false.
If I remove the validation for :active_flag, then I get a database error
because it tries to update it to null, and nulls are not allowed for
this column.
To correct myself, 0 is not a boolean false in ruby. I’m not sure if
it is in rails but I doubt it. The only thing that’s false in ruby is
the constant false.
In addition to craigs idea you might try running the breakpointer
right before the save! and just looking at the values as well as
trying to change the var and save manually. Breakpointer rocks
mightily.
Cheers,
Chuck V.
To correct myself, 0 is not a boolean false in ruby. I’m not sure if
it is in rails but I doubt it. The only thing that’s false in ruby is
the constant false.
-Chuck
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.