0
我的主要记录是Plate(如在车牌中)。
它可以有许多翻译(含义或评论)。
在一个页面上我想:
1)显示板记录,并允许用户进行评分板
2)显示所有现有的翻译记录,并允许用户把票投给一个
3)允许用户创建新的翻译记录
我正在使用form_for Plate和fields_for作为现有翻译记录。
我的研究表明应该有办法做到这一点,但我的代码没有提供一个空白表单。目前我正在尝试第二个fields_for循环。
目前,我只是专注于我的渲染表单页面,我还没有得到处理输入。 最终fields_for旨在为新翻译输入显示空白框,而不是显示最后一个现有翻译。
我会很感激任何建议。
下面是我的编辑形式:_rate_or_vote.html.erbRails如何在一个页面上显示现有的关联记录并允许新的关联记录输入
<!-- app/views/plates/_rate_or_vote.html.erb -->
<%= form_for(@plate) do |f| %>
<% if @plate.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@plate.errors.count, "error") %>
prohibited this plate from being updated:</h2>
<ul>
<% @plate.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<h1>Rate the Plate</h1>
<span class="form-group">
<%= f.label :input_rating, "Your Plate Rating" %>
<%= f.select :input_rating, options_for_select(RATINGS) %>
</span>  
<span class="form-group">
<%= f.label :rating, "Average Rating" %>
<%= f.text_field :rating , :value => (number_with_precision(f.object.rating, :precision => 2) || 0) %>
</span>  
<span class="form-group">
<%= f.label :plate_number, "Plate Number" %>
<%= f.text_field :plate_number %>
</span>  
<span class="form-group">
<%= f.label :state, "State" %>
<%= f.text_field :state, class: "form-control" %>
</span><br><br>
<span style="background-color:#DCDCDC; color:#000000; font-style: normal; font-family:Georgia;">
Contributor</span>
<span style="border:1px solid black;padding:3pt;">
<%= @plate.user.full_name %></span>  
<span class="form-group">
<%= f.label :plate_image, "Plate Image File" %>
<%= f.file_field :plate_image %>
</span><br><br>
<h1>Existing Translations and/or Comments - You can vote for one</h1>
<!-- %= f.fields_for :translations do |ff| %-->
<%= f.fields_for :translations, @plate.translations do |ff| %>
<span>Click this box to vote for this translation:</span> 
<span><%= check_box_tag "translation_ids[]", :id %></span>  
<span><%= ff.label "Current votes" %>
<%= ff.text_field :votes, :value => (number_to_percentage(ff.object.votes/(@plate.translation_votes.nonzero? || 1) * 100,
precision: 0)) %>
</span>  
<span style="background-color:#DCDCDC; color:#000000; font-style: normal; font-family:Georgia;">
Contributor</span>
<span style="border:1px solid black;padding:3pt;">
<%= ff.object.user.full_name %></span><br><br>
<span>Translation and/or Comment</span><br>
<span>
<%= ff.text_area :meaning, :cols => 60, :rows => 10 %>
</span><br><br>
<% end %>
<h1>Offer a new Translation and/or Comment</h1>
<!-- %= f.fields_for :translations do |ff| %-->
<%= f.fields_for :translations, @plate.translations do |fff| %>
<div>
<!-- %= fff.label :meaning, "Translation" %-->
<%= fff.text_field :meaning %>
</div><br><br>
<% end %>
<%= f.submit "Save and/or Return", :name => "update", class: "btn btn-default" %>