MongoDB booleans #635

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

Comments

Projects
None yet
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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Jul 30, 2012

Collaborator

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

Collaborator

rafaelfranca commented Jul 30, 2012

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

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Aug 11, 2012

Collaborator

@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.

Collaborator

carlosantoniodasilva commented Aug 11, 2012

@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.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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.

ghost 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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Nov 7, 2012

Collaborator

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.

Collaborator

rafaelfranca commented Nov 7, 2012

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

This comment has been minimized.

Show comment
Hide comment
@nashby

nashby Nov 7, 2012

Collaborator

@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?

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Nov 7, 2012

Collaborator

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

Collaborator

rafaelfranca commented Nov 7, 2012

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

@luckyjazzbo

This comment has been minimized.

Show comment
Hide comment
@luckyjazzbo

luckyjazzbo Aug 9, 2014

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

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