4

我在模型的一页 2 表格上User- 这就是问题所在,为什么我会收到错误消息Uncaught TypeError: Cannot read property 'presence' of undefined。当我删除一个form_for @user时,客户端验证运行良好。但如果在一页上有两个模型和两个表单@user 则不是

但问题是,我需要在一个页面上有这个模型并形成两次。有没有办法解决这个问题?

4

2 回答 2

2

For me, the second error you describe in the comments, i.e. Uncaught TypeError: Cannot read property 'first_user[name]' of undefined was apparently caused by a transposed form ID.

There is an issue on ClientSideValidation about it here:

https://github.com/bcardarella/client_side_validations/issues/325

Adding html => { id: 'user_new' } to the form_for call solved the issue. I now call the method like this (modified from Devise's original template):

<%= form_for(resource,
  :as => resource_name,
  :validate => true,
  :html => { id: 'user_new' },
  :url => registration_path(resource_name)) do |f| %>

HTH.

于 2012-05-28T12:08:23.923 回答
1

确保为两个用户使用不同的参数标识符:

<!-- First form for user -->
<%= form_for(@user, :as => :first_user) do |f| %>
  ...
<% end %>

<!-- Second form for user on the same page -->
<%= form_for(@user, :as => :second_user) do |f| %>
  ...
<% end %>
于 2012-05-14T10:10:47.120 回答