title: undefined method `to_i' for #<TrainerRate:0x007fd61f5b1150>
body: <p>I'm building checkboxes from a nested model, but somehow I'm stuck with this issue, it's been working pretty fine with similar forms but it's stuck here, from what I could presume is it's somehow converting my model primary key to be an integer while I'm using Mongoid and my object keys are in string, here are details, any help/recommendation in this regard is highly appreciated and will accept the answer right away. </p>
  
  <p>Error:</p>
  
  <pre><code>Showing _form.html.erb where line #31 raised:
  
  undefined method `to_i' for #&lt;TrainerRate:0x007fd61d9d7470&gt;
  </code></pre>
  
  <p>Error is coming up on to.check_box line.
  View code:</p>
  
  <pre><code> &lt;%= f.fields_for :booking_details do |to| %&gt;
  
              &lt;% ScheduleSlot.all.each do |tr| %&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;%= tr.hour_from %&gt;&lt;/td&gt;
                  &lt;td&gt;$&lt;%= @user.peak_rate %&gt;/Hour&lt;/td&gt;
                  &lt;% ScheduleSlotDay.all.each do |scd| %&gt;
  
                      &lt;% ob = @trainer_rates.where(:schedule_slot_day=&gt;scd._id,:schedule_slot=&gt;tr._id).first %&gt;
                      &lt;td&gt; &lt;label&gt;  &lt;%= to.check_box :trainer_rate %&gt;$&lt;%= ob.rate %&gt;/hr&lt;/label&gt;&lt;/td&gt;
                  &lt;% end
  
                  %&gt;
                &lt;/tr&gt;
            &lt;% end %&gt;
  </code></pre>
  
  <p>In controller if I change the trainer_rate:f._id to 1 it works fine bring up the checkboxes but they're not what I actually need, they don't have right ids naturally, so problem lies somewhere there. </p>
  
  <p>Controller Code (relevant action only):</p>
  
  <pre><code>def new
    @booking = Booking.new
    @user = User.find(params[:user])
    @consumer = User.new
    @trainer_rates = TrainerRate.where({user:@user._id}).all
  
    @trainer_rates.each do |f|
      @booking.booking_details.build trainer_rate:f._id
    end
  
    @booking.build_consumer
  </code></pre>
  
  <p>end</p>
  
  <p>Booking Model (relevant portion only):</p>
  
  <pre><code>accepts_nested_attributes_for :booking_details
  
  def booking_details_attributes=(details_attributes)
    details_attributes.each do |attributes|
      booking_details.build(attributes)
    end
  end
  </code></pre>
  
  <p>Booking Detail Model (relevant portion):</p>
  
  <pre><code>belongs_to :booking
  belongs_to :trainer_rate
  </code></pre>
  
  <p>TrainerRate Mode (as suggested in comments):</p>
  
  <pre><code>class TrainerRate
    include Mongoid::Document
    field :rate, type: Float
    belongs_to :schedule_slot_day
    belongs_to :user
    belongs_to :schedule_slot
    has_many :booking_details
  end
  </code></pre>
  
  <p>Complete stack trace:</p>
  
  <pre><code>    /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/proxy.rb:150:in `method_missing'
  actionpack (4.0.0) lib/action_view/helpers/tags/check_box.rb:53:in `checked?'
  actionpack (4.0.0) lib/action_view/helpers/tags/checkable.rb:10:in `input_checked?'
  actionpack (4.0.0) lib/action_view/helpers/tags/check_box.rb:19:in `render'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:930:in `check_box'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1649:in `check_box'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:648:in `yield_document'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:123:in `block in each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `block in each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `each'
  moped (2.0.0.beta6) lib/moped/query.rb:77:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:122:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual.rb:20:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:648:in `yield_document'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:123:in `block in each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `block in each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `each'
  moped (2.0.0.beta6) lib/moped/cursor.rb:28:in `each'
  moped (2.0.0.beta6) lib/moped/query.rb:77:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual/mongo.rb:122:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/contextual.rb:20:in `each'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1864:in `block in fields_for_nested_model'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:699:in `fields_for'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1863:in `fields_for_nested_model'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1849:in `block in fields_for_with_nested_attributes'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/referenced/many.rb:165:in `block in each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/targets/enumerable.rb:188:in `block in each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/targets/enumerable.rb:187:in `each_pair'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/targets/enumerable.rb:187:in `each'
  /Users/mohammadusman/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-5b0f031992cb/lib/mongoid/relations/referenced/many.rb:165:in `each'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1847:in `fields_for_with_nested_attributes'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:1521:in `fields_for'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
  actionpack (4.0.0) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  actionpack (4.0.0) lib/action_view/helpers/form_helper.rb:435:in `form_for'
  actionpack (4.0.0) lib/action_view/template.rb:143:in `block in render'
  activesupport (4.0.0) lib/active_support/notifications.rb:161:in `instrument'
  actionpack (4.0.0) lib/action_view/template.rb:141:in `render'
  actionpack (4.0.0) lib/action_view/renderer/partial_renderer.rb:306:in `render_partial'
  actionpack (4.0.0) lib/action_view/renderer/partial_renderer.rb:279:in `block in render'
  actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (4.0.0) lib/action_view/renderer/partial_renderer.rb:278:in `render'
  actionpack (4.0.0) lib/action_view/renderer/renderer.rb:47:in `render_partial'
  actionpack (4.0.0) lib/action_view/helpers/rendering_helper.rb:27:in `render'
  actionpack (4.0.0) lib/action_view/template.rb:143:in `block in render'
  activesupport (4.0.0) lib/active_support/notifications.rb:161:in `instrument'
  actionpack (4.0.0) lib/action_view/template.rb:141:in `render'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
  actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:17:in `render'
  actionpack (4.0.0) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionpack (4.0.0) lib/action_view/renderer/renderer.rb:23:in `render'
  actionpack (4.0.0) lib/abstract_controller/rendering.rb:127:in `_render_template'
  actionpack (4.0.0) lib/action_controller/metal/streaming.rb:219:in `_render_template'
  actionpack (4.0.0) lib/abstract_controller/rendering.rb:120:in `render_to_body'
  actionpack (4.0.0) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
  actionpack (4.0.0) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
  actionpack (4.0.0) lib/abstract_controller/rendering.rb:97:in `render'
  actionpack (4.0.0) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.0.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/mohammadusman/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
  activesupport (4.0.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
  remotipart (1.2.1) lib/remotipart/render_overrides.rb:14:in `render_with_remotipart'
  actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__1358898418329927427__process_action__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1221675166191648576__call__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /Users/mohammadusman/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /Users/mohammadusman/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /Users/mohammadusman/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
  </code></pre>