I have a Rails model called User
. There are two different types of users. Some users have company_profiles
in a separate table.
In my controller for my page view, I'd only like to display those users who have company_profiles. I'd also like to display their user info and their company_profile info too.
I'm not sure how to handle this in my controller and view.
What should be in my index method?
def index
@users = User.scoped # ?????
end
And how do I loop through each user with a company profile on the index page?
<% @users.each do |user| %>
<p>
<%= user.email %>
<%= user.company_profile.poc_first_name %>
</p>
<% end %>