I think i'm missing something really simple...
I'm trying to call a partial (located in vdrop\_vdrops.html.erb
) from another controller (in the calculators\index.html.erb
view). I have variables that need to be passed back to the calculators index upon submittal for display. When I pass render partial: 'vdrops/vdrop', collection: @vdrops
(see below) it just brings up the calculators index page without the partial. I am wondering if it's that I'm calling render
back to the 'calculators/index'
in the vdrops_controller.rb
as to why I cannot get this to work properly? When I pull out the partial by itself, or call it out of it's own view, I can get it to display and submit the data back to itself and display the previously submitted data properly.
Any help is greatly appreciated!!
Here's my index code:
<div class="calculator index">
<h2>Calculators Index Page</h2>
<%= render partial: 'vdrops/vdrop', collection: @vdrops %>
</div>
partial
<div>
<table class="table table-condensed">
<tr>
<th>Item</th>
<th>Amps</th>
<th>Volts</th>
<th>Distance</th>
<th>VDrop</th>
<th>KCMil</th>
</tr>
<%= form_tag ({:controller => 'Calculators', :action => 'index'}), :method => :get do %>
Phase: <%= select_tag :phase, options_for_select(Vdrop::PHASE_TYPE) %>
<tr>
<td></td>
<td><%= number_field_tag :amps , nil %></td>
<td><%= select_tag :volts, options_for_select(Vdrop::VOLTS_TYPE) %></td>
<td><%= number_field_tag :distance, nil %></td>
<td><%= number_field_tag :vdrop, nil %></td>
<td><%= @kcmil %></td>
</tr>
<td></td>
<td><%# @calc1[0] %></td> [these are commented out because they were causing an error]
<td><%# @calc1[1] %></td>
<td><%# @calc1[2] %></td>
<td><%# @calc1[4] %></td>
<td><%# @calc1[5] %></td>
</tr>
</table>
<%= submit_tag('Submit')%><br /><br />
<%= @calc1.inspect %>
<% end %>
</div>
Vdrops controller
class VdropsController < ApplicationController
def index
@amps = params[:amps].to_i
@volts = params[:volts].to_i
@distance = params[:distance].to_i
@phase = params[:phase].to_i
@vdrop = params[:vdrop].to_i
if @phase == 1
@kcmil = ((2 * 12.9 * @distance * @amps) / @vdrop).round(2)
else
@kcmil = ((1.73205080756887 * 12.9 * @distance * @amps) / @vdrop).round(2)
end
@calc1 = [@amps, @volts, @distance, @phase, @vdrop, @kcmil]
render "calculators/index"
end
end