I am trying to show all the companies in a portfolio in Rail 7 and can't figure out the right variable(s) to pass from the Portfolios page to the Companies partial. The companies model has_many: portfolios and Portfolios has_many: companies. Any help would be greatly appreciated.
In Portfolios\index.html.erb, I have tried
<%= render "portfolios/companies", company: portfolio.company_id%>
<%= render "portfolios/companies", @company %>
<%= render "portfolios/companies", portfolio: @portfolio %>
In the partial porfolios/_companies.html.erd, I have tried
<%= render portfolio.companies %>
<%= render 'companies/company', @company %>
Each had different errors, such as NilClass and "Undefined local variable or method `company'"
It sounds like you want to display every company for every portfolio on one page... that sounds a little messy but it can be done.
This assumes your
indexaction sets@portfolios. Inportfolios\index.html.erb:Then in
porfolios/_companies.html.erb, thecompaniesvariable would contain a collection of companies:The result should look something like:
