2012-09-07 48 views
0

我想在rails中引用當前用戶的值。當前用戶通過authlogic登錄,但錯誤不存在。難道我做錯了什麼?我只想保持安全並告訴他們爲什麼他們不能輸入地址。Rails authlogic/user無法檢查錯誤。

<%= form_for(current_user.address.build) do |f| %> 
    <% if current_user.address.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(current_user.address.errors.count, "error") %> prohibited this user from being saved:</h2> 

     <ul> 
     <% current_user.address.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

錯誤:

undefined method `errors' for #<ActionView::Helpers::FormBuilder:0x007f9584665e88> 

回答

0

刪除.any?再次嘗試,運氣好
也可以使用.present?方法或.blank?

+0

我不認爲它使那麼遠。 '錯誤'的方法沒有定義,所以我不能與它交互我可以返回?感謝您的答覆! – Lethjakman

+0

你解決了你的問題?你可以使用'try()'方法 – achempion