gettalong asked:

How to set a boolean field to false via @obj.assign (request)

Tags: 0.31

Hi!

I have a model which has a boolean field, an XHTML file which renders a form for updating the model and a controller which does the actual updating. I can set the boolean field to true via the form but not to false. @obj.assign(request) does not seem to work.

So, is there a way to set a boolean field to either true or false via the assign method?

Thanks!

(1 attempts)

Rayman answered:

unchecked checkboxes are set to false with .assign()

you could also try:

class Foo
  property :bar, TrueClass
  
  def bar=(val)
    @bar = false unless val.to_s.length > 0
  end
end

Or similar. Code not tested.

Rating: 3