Rails3客户端验证问题

时间:2011-05-16 15:58:56

标签: ruby-on-rails-3 devise

一直在观看Ryan优秀的截屏视频和这一集(#263 client_side_validations),他说要在_form.html.erb文件中添加以下代码行:

<%= form_for @user, :validate => true do |f| %>

但是,如果用户安装了Devise,他们会将代码放入new.html.erb文件中,其中已在顶部安装以下代码,从而产生错误:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name))     do |f| %>

有关如何使其发挥作用的任何想法?

Devise / registrations中的SyntaxError #new

 /app/views/devise/registrations/new.html.erb where line #4 raised:

 compile error
 /app/views/devise/registrations/new.html.erb:4: syntax error, unexpected tIDENTIFIER,   expecting kEND
 ...tion_path(resource_name)) user, validate => do |f| @output_b...
                          ^
 app/views/devise/registrations/new.html.erb:4: syntax error, unexpected tASSOC, expecting '='
 ...ource_name)) user, validate => do |f| @output_buffer.safe_co...
                          ^
 app/views/devise/registrations/new.html.erb:26: syntax error, unexpected kENSURE, expecting $end
 Extracted source (around line #4):

1: 
2: <h2>Sign Up</h2>
3: 
 4: <%= form_for  (resource, :as => resource_name, :url => registration_path(resource_name)) user, validate => do |f| %>
5:  <%= devise_error_messages! %>
6: 
7:   <p><%= f.label :username %><br />

THX。

1 个答案:

答案 0 :(得分:2)

试试这个:

<%= form_for(resource, :validate => true, :as => resource_name, :url => registration_path(resource_name))     do |f| %>