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

Aliased fields seem to fail validation in forms

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

      I've got an issue with validations on aliased fields and I'm not sure whether it's an issue with Mongoid or maybe ActiveModel. Tested with Mongoid master, Rails 4 RC1, RC2 and final.

      class Page
      include Mongoid::Document

      field :h, as: :hidden, type: Boolean, default: false
      validates :hidden, inclusion:

      { in: [true, false] }

      end

      When I use form helpers in my views that use the alias name, e.g.

      <%= f.check_box :hidden %>

      I always get the validation error 'Hidden is not included in the list', even though the checkbox value shows up correctly in the params as a value that should be treated as boolean.

      If I use the form helper on the original field name, it passes validation:

      <%= f.check_box :h %>

      Is that intended behaviour? It only seems to be an issue with form helpers, when I manually set the fields on objects it works fine no matter if I set the aliased name or the original, e.g.

      page.h = "1"

      will be valid just like

      page.hidden = "1"

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

              Created:
              Updated:
              Resolved: