2012-04-19 95 views
0

我想用這種方法取記錄在Ruby on Rails的

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

但是當我嘗試迭代它,它告訴我一些錯誤得到ROR一些領域的基礎上的紀錄。

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

請讓我知道我做錯了。

回答

3

這是因爲你正在得到一個具體的對象而不是迭代的關係。你會,而不是需要改變你的取景器,如:

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

使用find_all_by_manager_id代替find_by_manager_id

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