0
我是Rails和Mongoid的新手。我正在嘗試創建一個登錄頁面。問題是如果有用戶名或密碼錯誤,我無法發出錯誤消息。以下是我的代碼。Mongoid的Rails:認證失敗時產生錯誤
型號user.rb
def self.authenticate(login, pass)
if user = first(:conditions => {:username => login})
return user if user.password==(pass)
end
return false
end
控制器user_auth.rb
查看login.html.erb
<% form_for(@user,:url => { :action => "login" }) do |d| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<%= pluralize(@user.errors.count, "error") %>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p> Your Name: <%= d.text_field :username %><br /> </p>
<p> Password: <%= d.password_field :password %><br/></p>
<p><%=d.submit "Login" %></p>
<% end %>