Surjan Singh
Surjan Singh

Reputation: 135

Fetch record in ruby on rails

I am trying to get the record on the basis of some field in ROR by this method

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

but when i try to iterate it , it show me some error.

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

related code:

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

Please let me know what i am doing wrong .

Upvotes: 0

Views: 84

Answers (2)

Pritesh Jain
Pritesh Jain

Reputation: 9146

use find_all_by_manager_id instead of find_by_manager_id

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

Upvotes: 0

Spyros
Spyros

Reputation: 48706

That is because you are getting a concrete object and not a relation to iterate with. You would instead need to change your finder like :

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

Upvotes: 3

Related Questions