I have two partials, that are almost exactly the same, except one is a full view, and the other is a compact. They are both under 'projects' view, but one works correctly, and the other gives errors:
projects/_project.html.erb
<div class="pure-u-1-3">
<%= link_to project do %>
<div class="project">
<h4 class="red marginless"><%= truncate( project.title, length: 22, separator: ' ') %></h4>
<p class="left marginless"><strong>By:</strong> <%= project.user.username %><br>
<strong>Genres:</strong> <%= truncate( project.genre2, length: 25, separator: ' ') %><br><br>
<strong>Description:</strong><br>
<%= truncate( project.description, length: 60, separator: ' ') %><br>
<strong>Needs:</strong><br>
<%= truncate( project.looking_for, length: 60, separator: ' ') %></p>
</div>
<% end %>
<% if @projects.size == 0 %>
<em> no projects found with that criteria </em>
<% end %>
</div>
projects/_short.html.erb
<div class="pure-u-1-3">
<%= link_to project do %>
<div class="project">
<h4 class="red marginless"><%= truncate( project.title, length: 22, separator: ' ') %></h4>
<p class="left marginless"><strong>By:</strong> <%= project.user.username %></p>
</div>
<% end %>
</div>
Now, this is the part of the view using these partials:
dashboards/index.html.erb
<% if @projects.length > 0 %>
<div class="pure-u-1" id="projects"><h3 class="red"><%= current_user.username %>'s Owned Projects</h3>
<%= render :partial => 'projects/short', :collection => @projects %>
</div>
<% end %>
When I have 'projects/project' it works perfectly, no issues. When I put 'projects/short' it gives me this error:
undefined local variable or method `project'
This error is given everywhere the word project is used on _short, unless I use @project, but then it gives me this error:
undefined method `title' for nil:NilClass (same for user)
I do not understand how the partials can be in the exact same spot, and used the exact same way, in the exact same spot, but one works and the other does not. Is there code I may have done in the past, that I am missing that makes this work?