bcardarella/client_side_validations — Issue #273: Validating Uniqueness on has_nested_attributes
Author: justin808
Created: 2012-02-11 19:59:10+00:00
State: open

I've got a class, Appointment, that has a belong_to relationship with User.
accepts_nested_attributes_for :user

You can edit the user's e-mail on the appointment record. The uniqueness validator (Devise setup) almost works perfectly. The problem is that the options hash that is passed to the validator does not contain the user_id in the id element, and thus an existing record will look invalid for uniqueness:

>>> options
Object { message="has already been taken", case_sensitive=true}

I'd like to know what I can do to get the validator to include the id in the validator options.

remote: {
uniqueness: function(element, options) {
var data, key, message, name, scope_value, scoped_element, scoped_name, _ref;
message = ClientSideValidations.validators.local.presence(element, options);
if (message) {
if (options.allow_blank === true) return;
return message;
}
data = {};
data.case_sensitive = !!options.case_sensitive;
if (options.id) data.id = options.id;