0

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 .

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

0

use find_all_by_manager_id instead of find_by_manager_id

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.