Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2594

undefined method `id' for :String

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.15
    • Affects Version/s: None
    • Component/s: None
    • None

      I can register but can not update the object ride. What is the solution for this? (I'm using Ruby 1.9.3, Rails 3.2.8 and MongoID 3.0.0)
      <b>the source code</b>
      https://github.com/candidosales/querocarona

      <b>NoMethodError in RidesController#update</b>
      <pre>undefined method `id' for "50b8290e4d7d2c51fa000006":String

      app/controllers/rides_controller.rb:40:in `update'
      </pre>
      <b>Parameters</b>
      <pre>{"utf8"=>"✓",
      "_method"=>"put",
      "authenticity_token"=>"Oc1Ip+sKe8tOEaT9pVMY3jU3KiP4G0gYFwfmRorIBr0=",
      "ride"=>

      {"driver"=>"50b8290e4d7d2c51fa000006", "requestor"=>"50b8290e4d7d2c51fa000006", "initial"=>"Centro", "destination"=>"JOckey"}

      ,
      "commit"=>"Update Ride",
      "id"=>"50b83b624d7d2c0f8000000b"}</pre>
      <b>log console</b>
      <pre>
      Started PUT "/rides/50b8297d4d7d2cd04b000008" for 127.0.0.1 at 2012-11-30 09:24:15 -0300
      Processing by RidesController#update as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"Oc1Ip+sKe8tOEaT9pVMY3jU3KiP4G0gYFwfmRorIBr0=", "ride"=>

      {"driver"=>"50b8290e4d7d2c51fa000006", "requestor"=>"50b83b544d7d2c230500000a", "initial"=>"Mocambinho", "destination"=>"Centro"}

      , "commit"=>"Update Ride", "id"=>"50b8297d4d7d2cd04b000008"}
      MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (1.1415ms)
      MOPED: 127.0.0.1:27017 QUERY database=querocarona_development collection=rides selector=

      {"_id"=>"50b8297d4d7d2cd04b000008"}

      flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4654ms)
      MOPED: 127.0.0.1:27017 QUERY database=querocarona_development collection=users selector={"$query"=>

      {"_id"=>"50b8290e4d7d2c51fa000006"}

      , "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (0.4120ms)
      MOPED: 127.0.0.1:27017 QUERY database=querocarona_development collection=rides selector={"$query"=>

      {"requestor_id"=>"50b8290e4d7d2c51fa000006"}

      , "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (0.5767ms)
      Completed 500 Internal Server Error in 7ms

      NoMethodError (undefined method `id' for "50b8290e4d7d2c51fa000006":String):
      app/controllers/rides_controller.rb:40:in `update'

      Rendered /home/candidosg/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.9ms)
      Rendered /home/candidosg/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.7ms)
      Rendered /home/candidosg/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (11.1ms)

      </pre>
      <b>RidesController#update</b><pre>def update
      @ride = Ride.find(params[:id])
      flash[:notice] = 'Ride was successfully updated.' if @ride.update_attributes(params[:ride])
      respond_with @ride
      end</pre>

      <b>model ride</b>
      <pre>
      class Ride
      include Mongoid::Document
      field :initial, type: String
      field :destination, type: String
      field :created_at, type: Time , default: Time.now

      belongs_to :driver, class_name: "User"
      belongs_to :requestor, class_name: "User"

      end

      </pre>

      <b>model user</b>
      <pre>
      class User
      include Mongoid::Document
      field :name, type: String
      field :username, type: String
      field :email, type: String

      has_one :ride, inverse_of: :driver
      has_one :ride, inverse_of: :requestor

      end
      </pre>

            Assignee:
            Unassigned Unassigned
            Reporter:
            candidosales candidosales
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: