我在寫一些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