得到未定义的方法`any?'错误

时间:2013-11-06 17:28:00

标签: ruby-on-rails ruby-on-rails-3.2

我正在关注Michael Hartl ROR教程,我正在尝试对用户关注者/后续页面进行分页,我收到一个错误,说未定义的方法`any?'那是为什么?

查看/用户/ show_follow.html.erb

 <div class="row">
<aside class="span4">
    <section>
        <%= gravatar_for @user %>
        <h1><%= @user.email %></h1>
        <span><%= link_to "view my profile", @user %></span>
    </section>
    <section>
        <%= render 'shared/stats' %>
        <% if @user.any? %>
        <div class="user_avatars">
            <% @users.each do |user| %>
                <%= link_to gravatar_for(user, size: 30), user %>
                <% end %>
            </div>
            <% end %>
    </section>
</aside>
<div class="span8">
    <h3><%= @title %></h3>
    <% if @users.any? %>
    <ul class="users">
        <%= render @users %>
    </ul>
    <%= will_paginate %>
    <% end %>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

any?仅适用于Enumerable。见这里:http://ruby-doc.org/core-2.0.0/Enumerable.html#method-i-any-3F

我怀疑<% if @user.any? %>应该是<% if @users.any? %>