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

Mongoid localized field not being set in first form submission

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0, 6.1.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I've asked this question on Stack Overflow but not had much luck: http://stackoverflow.com/questions/29899935/mongoid-localized-field-not-being-set-in-first-form-submission

      Environment:
      Rails 4.2.0
      Ruby 2.1.2
      Mongoid 4.0.0

      I have a simple_form with fields name, and display_name. Both are localised => true but name is disabled on the form.

      When I submit the form with a value in display_name Mongoid doesn't see the value for display_name, i.e. "dn"=>

      Started PATCH "/admin/competitions/53d11b01736e7358b57a0000" for ::1 at 2015-04-27 16:20:11 +0100
          Processing by Admin::CompetitionsController#update as HTML
            Parameters: {"utf8"=>"✓", "authenticity_token"=>"[hidden]", "competition"=>{"display_name"=>"Capital One Cup", "country_id"=>"53d11af2736e7358b5190000"}, "commit"=>"Update Competition", "id"=>"53d11b01736e7358b57a0000"}
          D, [2015-04-27T16:20:11.537579 #5896] DEBUG -- :   MOPED: 127.0.0.1:27017 QUERY        database=dev collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('53f74b79736e73452f000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 1.7300ms
          D, [2015-04-27T16:20:11.539357 #5896] DEBUG -- :   MOPED: 127.0.0.1:27017 QUERY        database=dev collection=competitions selector={"_id"=>BSON::ObjectId('53d11b01736e7358b57a0000')} flags=[] limit=0 skip=0 batch_size=nil fields=nil runtime: 0.5760ms
          D, [2015-04-27T16:20:11.561547 #5896] DEBUG -- :   MOPED: 127.0.0.1:27017 UPDATE       database=dev collection=competitions selector={"_id"=>BSON::ObjectId('53d11b01736e7358b57a0000')} update={"$set"=>{"dn"=>{}, "updated_at"=>2015-04-27 15:20:11 UTC}} flags=[]
          D, [2015-04-27T16:20:11.561685 #5896] DEBUG -- :                          COMMAND      database=dev command={:getlasterror=>1, :w=>1} runtime: 18.4320ms
          Redirected to http://localhost:3000/admin/competitions
          Completed 302 Found in 39ms
      

      Now if I edit the object and give it a display name again Mongoid picks up the change and writes it to the DB. i.e. {{"dn"=>

      {"en"=>"Capital One Cup"}}}
      
      

      Started PATCH "/admin/competitions/53d11b01736e7358b57a0000" for ::1 at 2015-04-27 16:25:34 +0100
      Processing by Admin::CompetitionsController#update as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"[hidden]", "competition"=>{"display_name"=>"Capital One Cup", "country_id"=>"53d11af2736e7358b5190000"}, "commit"=>"Update Competition", "id"=>"53d11b01736e7358b57a0000"}
      D, 2015-04-27T16:25:34.465519 #5896 DEBUG – : MOPED: 127.0.0.1:27017 QUERY database=dev collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('53f74b79736e73452f000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.8160ms
      D, 2015-04-27T16:25:34.469391 #5896 DEBUG – : MOPED: 127.0.0.1:27017 QUERY database=dev collection=competitions selector={"_id"=>BSON::ObjectId('53d11b01736e7358b57a0000')} flags=[] limit=0 skip=0 batch_size=nil fields=nil runtime: 0.5070ms
      D, 2015-04-27T16:25:34.497381 #5896 DEBUG – : MOPED: 127.0.0.1:27017 UPDATE database=dev collection=competitions selector={"_id"=>BSON::ObjectId('53d11b01736e7358b57a0000')} update={"$set"=>{"dn"=>{"en"=>"Capital One Cup"}

      , "updated_at"=>2015-04-27 15:25:34 UTC}} flags=[]
      D, 2015-04-27T16:25:34.497525 #5896 DEBUG – : COMMAND database=dev command={:getlasterror=>1, :w=>1} runtime: 23.9000ms
      Redirected to http://localhost:3000/admin/competitions
      Completed 302 Found in 39ms

      
      

      In config/application.rb I have set:

      config.i18n.fallbacks = true
      config.i18n.default_locale = :en

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            james-ai james-ai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: