Find_all
So the first thing I had to do was figure out how to query which assets were related to which projects, that we connected last time. This isn’t to hard open up script/console and type - Asset.find_all_by_project_id(1) . But then I was stuck now what? I already setup the has many, and I could query on the command line but I was lost as what to do next.
So after a brief call to a friend my eyes were opened on how to go from pure Ruby to Rails. In my projects controller I already have from scaffolding - @project = Project.find(params:id) . Now I need to setup a local variable - @assets = @project.assets
In my show template for projects I just query -
<div id="assets">
<% @assets.each { |a| %>
<b>Asset :</b>
<%= render(:partial => '/assets/list_item', :object => a)%>
<br />
<% } %>
</div>
In the assets I have setup a partial called list_item which is used to print out the items in the assets index view. All in all very clean and simple.