-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
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:
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"