0

この方法でRORのいくつかのフィールドに基づいてレコードを取得しようとしています

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

しかし、それを反復しようとすると、エラーが表示されます。

undefined method each' for undefined method each' for #<Profile:0x8383680>

関連コード:

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

私が間違っていることを教えてください。

4

2 に答える 2

3

これは、反復する関係ではなく、具体的なオブジェクトを取得しているためです。代わりに、ファインダーを次のように変更する必要があります。

@indivisuals = Profile.where(:manager_id => current_user.account.id)
于 2012-04-19T20:29:45.133 に答える
0

find_all_by_manager_idの代わりに使用find_by_manager_id

@indivisuals = Profile.find_all_by_manager_id(current_user.account.id)  
于 2012-08-11T12:24:56.383 に答える