我想我错过了一些非常简单的事情......
我试图从另一个控制器(在vdrop\_vdrops.html.erb
视图中)调用部分(位于calculators\index.html.erb
)。我有变量需要在提交显示时传回计算器索引。当我通过render partial: 'vdrops/vdrop', collection: @vdrops
(见下文)时,它只显示计算器索引页面而没有部分。我想知道我是否正在调用render
回'calculators/index'
中的vdrops_controller.rb
,以了解为什么我无法正常使用此功能?当我自己拿出部分内容,或者从它自己的视图中调出它时,我可以让它显示并将数据提交回自身并正确显示以前提交的数据。
非常感谢任何帮助!!
这是我的索引代码:
<div class="calculator index">
<h2>Calculators Index Page</h2>
<%= render partial: 'vdrops/vdrop', collection: @vdrops %>
</div>
部分
<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控制器
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