I am trying to build my partials and repeat less, but I am having a problem. The following works just fine:
In view:
<%= render 'valve' %>
In partial:
<% if @valve.length > 1 %>
<h3>Valve kit</h3>
<%= render 'not_enough' %>
<% else if @valve.length < 1 %>
<h3>Valve kit</h3>
I am going to have many kits, so rather than repeating this for every kit variable, I would like to do something like this:
<%= render :partial => 'valve', :object => @valve %>
<% if valve.length > 1 %>
<h3>Valve kit</h3>
<%= render 'not_enough' %>
<% else if valve.length < 1 %>
<h3>Valve kit</h3>
But that breaks the valve.length method. So, what is changing when I pass @valve as the :object? Is there another method I can use as a substitute to accomplish the same functionality in the partial?
You need to pass a :locals hash to the partial
Then use valve.* in your view like you have. Try to avoid using instance variables in partials when possible.