Skip to content


Subversion checkout URL

You can clone with
Download ZIP


undefined method `each' for "":String (mongoid/middleware.rb:13:in `is_unique?' ruby1.9.2) #26

fwoeck opened this Issue · 11 comments

2 participants


Hi Brian!

When I fire a[email]

I get an
undefined method `each' for "":String

error here:
lib/client_side_validations/mongoid/middleware.rb:13:in `is_unique?'

That's this line:
(params[:scope] || {}).each do |key, value|

Could it be, that in this case params[:scope] is not a Hash but a string and ruby1.9.2 bails out?


Hi Frank,

Does the validation in the model have a scope?

What I'm seeing is the scope param has no value in the URL you included. Client Side Validations should set a default value for the scope for an existing record, but if the scope is for an attribute that is on the current form the value of that attribute on the form will override the default value.

I develop on 1.9.2 so I don't think that's a factor in this case.

If you could paste in the model as well as the form that would be a great help. Thanks! :)


I'm guessing that this is a new record and the value for that scope can not be derived from the form. (either it hasn't been entered in or it is set on the server when creating the record)


If this is the case there is a strategy to have this work:

On the controller set the attribute on the model to be validated that will be scoped against. This will set the default scope value the validations will use.

In any case, this a legit bug. If the scope param is empty, and there are cases that it can be, it should just fall back to a server side validation instead of crashing. I'll include as a bug for 3.0.1. Thanks! :)


Thank you for your quick reply! I'm not sure if I understand "scope" fully. Actually the controller action to render the form stems from devise, it's a session controller:

def new
render_with_scope :new

And the form looks like this:

= form_for(resource, :as => resource_name, :url => session_path(resource_name), :validate => true) do |f|
= f.label :email
= f.email_field :email

Im terms of mongoid "scopes" there's no default scope defined - but this is not what you mean, right?



Is this a default devise generated model?


basically yes, with lot of added stuff. It looks like this:

validates_presence_of :email

attr_accessible :email, :password, :password_confirmation,
:name, :color, :avatar

devise :database_authenticatable,


Ok, thanks very much. I'll start digging into it.


Ok, thank you for your work!


Fixed in: 7faa2f6

@bcardarella bcardarella closed this

cool, thank you!


3.0.1 is pushed so it should be all good. Let me know if anything else comes up! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.