Skip to content

MongoDB booleans #635

Closed
rutte opened this Issue Jul 26, 2012 · 7 comments

6 participants

@rutte
rutte commented Jul 26, 2012

MongoDB Boolean fields (which are of type Boolean) renders text field instead of checkbox.

Added:
Must confess I have only tried with the Mongoid wrapper.

@rafaelfranca

We don't support MongoID integration in SimpleForm, but I'll be glad to accept a pull request to make this work.

@rafaelfranca rafaelfranca reopened this Jul 30, 2012
@carlosantoniodasilva

@rutte would you mind sharing the model you're using with SimpleForm, and the form code? This would help us or someone else to work on this. Thanks.

@xanview
xanview commented Sep 2, 2012

I'm using default scaffolds, my model looks like this:

class Event
  include Mongoid::Document
  field :complete, type: Boolean, default: false

My view looks like this:

= simple_form_for(@scope) do |f|
  = f.error_notification

  .form-inputs
    = f.input :complete

  .form-actions
    = f.button :submit

The :complete field is rendered as a textfield instead of the expected checkbox for boolean.

@rafaelfranca

Since we don't support Mongoid we can't discovery what kind is the field. You have to pass the type using the :as option.

@nashby
nashby commented Nov 7, 2012

@rafaelfranca I was thinking about using orm_adapter to solve this issue. Unfortunately it doesn't support column_type or similar method so I was going to add it. Do you think its worth it? Or we don't need another dependency?

@rafaelfranca

I don't think is worth right now since you can use the :as options. Maybe in the future we can support mongoid.

@luckyjazzbo

Dirty patch to Mongoid::Document

module Mongoid
  module Document
    ARFakeColumn = Struct.new(:type, :limit, :number?)

    def column_for_attribute(attribute_name)
      if fields[attribute_name.to_s].options[:type] == Mongoid::Boolean
        ARFakeColumn.new(:boolean, 0)
      else
        ARFakeColumn.new(:string, 0)
      end
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.