I am using these gem versions:
gem 'rails', '4.0.1'
gem 'mongoid', '~> 4', github: 'mongoid/mongoid'
gem 'devise', '3.2.0'
I am trying to pass a boolean choice to mongoid with this form:
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= f.check_box :tos_agreement
= t(".do_you_accept_our_toc")
My model looks like this:
class User
include Mongoid::Document
field :tos_agreement, :type => Boolean
The server log says this:
Started POST "/da/users" for 127.0.0.1 at 2013-11-13 19:41:32 +0100
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nyfk//kJtXXM1MMSWln5fTn4P2vzzeP4XzgC3GTT/tk=", "user"=>{"tos_agreement"=>"1"}, "commit"=>"Create", "locale"=>"en"}
MOPED: 127.0.0.1:27017 QUERY database=mydb_development collection=users selector={"email"=>"example@gmail.com"} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 0.9030ms
As you can see, "1"
is passed from the form, but I have also tried with "yes"
and "true"
.
When I fire up the console, I can see that a boolean has not been injected, instead the string has:
2.0.0p247 :001 > User.last
=> #<User _id: 5283c38563687282c5000000, email: "example@gmail.com", tos_agreement: "1">
What can I do to insert a boolean value?