Rails authlogic / user无法检查错误。

时间:2012-09-07 18:55:50

标签: ruby-on-rails ruby-on-rails-3 activerecord authlogic

我正在尝试在rails中引用当前用户的值。当前用户通过authlogic登录,但错误不存在。难道我做错了什么?我只是想安全并告诉他们为什么他们不能输入地址。

<%= 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>

1 个答案:

答案 0 :(得分:0)

删除.any?再试一次,祝你好运 您也可以使用.present?方法或.blank?