【发布时间】:2011-06-11 15:48:10
【问题描述】:
我正在使用 formtastic 来验证表单:
<%= semantic_form_for @user do |f| %>
<ul class="formItem">
<%= f.input :username, :required => true, :label => "Your Username", :input_html => { :class => 'double' } %><br clear="all" />
<p class="fieldExplanation">Your username is made public to other people on the site.</p>
</ul>
<ul class="actions">
<%= f.commit_button("Save my profile and make a match >", :class => "submitForm") %>
</ul>
<% end %>
它在视觉上是有效的 - 表单带有一个小星号,表示它理解 :required => true - 但是当页面发布时,它不会触发错误验证;相反,它只是移动到下一页,就好像它成功了一样。
我觉得我在某处缺少一个简单的设置来打开验证,或者我的控制器做错了什么?
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(match_user_path(@user), :notice => 'User was successfully updated.') }
else
format.html { render :action => "edit" }
end
end
end
提前致谢。
【问题讨论】:
-
我开始认为还有其他问题 - 当我包含
<%= f.input :mySelectBox, as => :select, :collection => ["Thing one", "Thing two"] %>时,我得到 undefined local variable or method `as' for #:0x837a368>
标签: ruby-on-rails ruby validation formtastic