我在写一些if/elsif语句来显示错误消息。当我将用户名留空并正确填写其他字段时,它仍会转到else语句并显示“所有字段必须完成”。有人能指出我的逻辑/语法错误吗?写入form_for错误消息的条件
<% if @user.errors.any? %>
<div id="error_explanation" class="round">
<% if @user[:name].nil? and @user[:email].not.nil? and @user[:password].not.nil? and @user[:password_digest].not.nil? %>
<h2>Please enter a valid username. </h2>
<% else %> <!--If any field is left blank -->
<h2>All fields must be completed. </h2>
<% end %>
</div>
<% end %>
让我知道你是否需要别的东西。
感谢您的链接! – Huy 2012-03-05 17:05:37
我在user.rb中为我的用户创建了我的验证测试。我上面的代码只是为了让访问者在网站上显示错误消息。视频方法比我目前的方法更有效吗? – Huy 2012-03-05 19:46:19
跟着视频,它的作品。再次感谢你,艾杰! – Huy 2012-03-05 19:58:45