在RubyonRails中获取记录

在RubyonRails中获取记录,ruby,database,ruby-on-rails-3,Ruby,Database,Ruby On Rails 3,我试图通过这种方法在ROR中的某个字段的基础上获取记录 @indivisuals = Profile.find_by_manager_id(current_user.account.id) 但是当我尝试迭代它时,它显示了一些错误 undefined method each' for undefined method each' for #<Profile:0x8383680> undefined method each'针对未定义的方法each'针对# 相关代码: <

我试图通过这种方法在ROR中的某个字段的基础上获取记录

@indivisuals = Profile.find_by_manager_id(current_user.account.id)  
但是当我尝试迭代它时,它显示了一些错误

undefined method each' for undefined method each' for #<Profile:0x8383680>
undefined method each'针对未定义的方法each'针对#
相关代码:

<% if @indivisuals %>
  <% @indivisuals.each do |profile| %>
  <li><a href="accounts/show/<%=h profile.account_id %>" style="padding-left:10px;"><%=h profile.full_name %></a>&nbsp;<a href="accounts/edit/<%=h profile.account_id %>" style="padding-left:10px;">Edit</a>&nbsp;&nbsp;<a href="#" style="padding-left:10px;">Delete</a></li>
<% end %>


  • 请让我知道我做错了什么。

    这是因为您得到的是一个具体的对象,而不是一个要迭代的关系。相反,您需要更改查找程序,如:

    @indivisuals = Profile.where(:manager_id => current_user.account.id)
    

    这是因为您得到的是一个具体的对象,而不是一个用于迭代的关系。相反,您需要更改查找程序,如:

    @indivisuals = Profile.where(:manager_id => current_user.account.id)
    

    使用
    find\u all\u by \u manager\u id
    而不是
    find\u by \u manager\u id

    @indivisuals = Profile.find_all_by_manager_id(current_user.account.id)  
    

    使用
    find\u all\u by \u manager\u id
    而不是
    find\u by \u manager\u id

    @indivisuals = Profile.find_all_by_manager_id(current_user.account.id)