我有一个名为cattle finances的表单,在这种形式中,我使用集合选择输入批号,我有其他表格列显示在_form.html.erb代码下面
<%= simple_form_for @cattle_finance, remote: true do |f| %>
<% if @cattle_finance.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@cattle_finance.errors.count, "error") %> prohibited this cattle_finance from being saved:</h2>
<ul>
<% @cattle_finance.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<br>
<%= f.collection_select :batch_number, CattleList.all, :batch_number, :batch_number, :prompt => "please select Batch Number" %></br>
<%= f.input :total_litres_of_batch, as: :integer %>
<%= f.input :total_income, as: :integer %>
<%= f.input :gross_income, as: :integer %>
<%= f.input :total_expenses, as: :integer %>
<%= f.input :net_income, as: :integer %>
<%= f.input :date, as: :date %>
<%= f.button :submit %>
<% end %>
我的index.html.erb代码是
<div class="row">
<div class="col-md-5 col-md-offset-1">
<h2>Cattle Finances</h2>
</div>
<div class"btn-group menu2" align = right>
<%= link_to raw("<span class=''></span> Creditors"), cattle_creditors_path, :class=>"btn btn-default" %>
<%= link_to raw("<span class=''></span> Debtors"), cattle_debtors_path, :class=>"btn btn-default" %>
<%= link_to raw("<span class=''></span> Cattle"), cattles_path, :class=>"btn btn-default" %>
<%= link_to "Home", root_path, :class=>"btn btn-default" unless current_page?(root_url) %>
</div>
<div class="col-md-2 col-md-offset-4">
<%= link_to new_cattle_finance_path, remote: true do %>
<button class="btn btn-default">New</button>
<% end %>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-2" id="cattle_finance-form" style="display:none;"></div>
</div>
<div class="row">
<div class="" id="cattle_finances"><%= render @cattle_finances %></div>
</div>
所以需要帮助的是我可以选择特定batch_number的方式,并自动填充所有其他字段,或者从相应的数据库表中分别从数据库中挑选并填写。尽管如此,任何帮助他高度赞赏的因素都会被卡住 我知道我想做什么,我不知道如何开始。