Devise `new_user` vs `user_new` bug (very odd) #325

coryschires opened this Issue May 2, 2012 · 2 comments

3 participants


Recently I noticed that live validations were no longer working on my devise signup form. They had worked previously and still worked everywhere else. Somehow I had broken devise validations.

My exact error was:

Uncaught TypeError: Cannot read property 'user[email]' of undefined     
Uncaught TypeError: Cannot read property 'user[password]' of undefined
# etc ... for each field as I tabbed through the form

My relevant gems are mostly up to date:

gem 'rails',                      '3.2.3'
gem 'client_side_validations',    '~> 3.1.4'
gem 'simple_form',                '~> 1.5.2'
gem 'devise',                     '~> 2.1.0.rc'
gem 'jquery-rails',               '~> 1.0.19'

After poking around for a quite a while I realized that the primary key of the validators object was somehow being transposed:

window['user_new'] = {"type": ... } # rather than ...
window['new_user'] = {"type": ... } # ... wtf?

So the (slightly hacky) fix is obvious. Just add a form id of user_new in order to override rails default id of new_user. So it should look something like:

simple_form_for(resource, as: resource_name, url: registration_path(resource_name), validate: true, html: { id: 'user_new' }) do |f|
  # devise fields ...

I don't mind adding the id. It's not the worst hack. This post is mostly for documentation in case someone else encounters the issue.

Nonetheless, I very confused about the root cause. If anyone wants to entertain my curiosity:

  • Has anyone else seen this?
  • @bcardarella Do you have any idea why this would happen?

Thanks for posting this, I came across the exact same issue. The above fix helped get me by the issue for the mean time.


This is a Devise specific issue. The solution here is to either set a custom id or, in the case of ClientSideValidations 3.2 to release a custom Devise plugin similar to

In any event, the code as-is for Rails default is correct.

@bcardarella bcardarella closed this Jul 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment