No has entrat com a usuari. Pots registrar-te o entrar. Així podràs crear entrades o comentar-ne d'altres!
Gravatar
0

We know each database handles boolean values on its own way. Fortunatelly enough ActiveRecord provides an abstraction layer that handles this for us, but sometimes we want to known in a POST action if the given parameters are true or not before actually save the model.

This is a simple method hidding in ActiveRecord internals to do that:

ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)

This is useful for example if we want to make a virtual boolean attribute, defining this in the model:

def bool_attr=(value)
  @bool_attr = ActiveRecord::ConnectionAdapters::Column.value_to_boolean value
end

And using it in the form as a normal attribute:

= f.check_box :bool_attr


0 comentaris