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

Mongoize & evolve ActionController::Parameters into Hash

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Attributes

      ActionController::Parameters need a mongoizer to convert them into Hash; currently an error is raised.

      • Note that a demongoize method is not needed here; the conversion should be one-way only.

      I have raised https://github.com/mongodb/mongoid/pull/5237 for this.

      The below demonstrates the issue.

      require 'mongoid'
      require 'action_controller'
      
      class Company
       include Mongoid::Document
      field :name, type: String, localize: true
      end
      
      params = ActionController::Parameters.new({ name_translations: { en: "Foobar", fr: "Bazqux" } }).permit!
      
      company = Company.new
      company.name_translations = params
      
      #=> 
      Traceback (most recent call last):
            3: from C:/ruby30/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
            2: from (irb):20:in `<main>' 
            1: from C:/ruby30/lib/ruby/gems/3.0.0/gems/mongoid-7.4.0/lib/mongoid/fields.rb:577:in `block (2 levels) in create_translations_setter'
      NoMethodError (undefined method `update_values' for #<ActionController::Parameters {"name_translations"=>#<ActionController::Parameters {"en"=>"Foobar", "fr"=>"Bazqux"} permitted: true>} permitted: true>)  

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: