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

callback, undefined method when setting self.attribute

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      <pre>
      class Place
      include Mongoid::Document
      embedded_in :anchor, :inverse_of => :places
      key :coord, :type => Array
      key :name, :type => String
      key :desc, :type => String
      key :address1, :type => String
      key :address2, :type => String
      key :city, :type => String
      key :zipcode, :type => Integer
      key :web_link, :type => String
      referenced_in :user, :inverse_of => :places
      embeds_many :comments

      before_save :get_location

      def get_location
      self.coord = [42.01937, -87.67328]
      end
      end
      </pre>
      When trying to run this callback, you get:
      <pre>
      Undefined method coord= for .... </pre>

            Assignee:
            Unassigned Unassigned
            Reporter:
            nicholaswyoung Nicholas Young
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: