我有一个像这样的rails更新表单:
<%= debug @ballot.scores %>
<%= simple_form_for(@ballot, :url => "/vote/#{@election.id}/ballot/#{@ballot.position}/submit", :method => :post, :html => {:class => 'form-horizontal' }) do |f| %>
<% f.fields_for :scores do |builder| %>
<div class="slider">Slider goes here!</div>
<%= builder.hidden_field :initialValue, :value => 50 %>
<% end %>
<%= f.button :submit %>
<% end %>
调试显示:
---
- !ruby/object:Score
attributes:
id: 1
ballot_id: 4
candidate_id: 4
initialScore:
normalizedScore:
created_at: 2013-08-08 05:00:10.391163000 Z
updated_at: 2013-08-08 05:00:10.432374000 Z
- !ruby/object:Score
attributes:
id: 2
ballot_id: 4
candidate_id: 5
initialScore:
normalizedScore:
created_at: 2013-08-08 05:00:10.418904000 Z
updated_at: 2013-08-08 05:00:10.434772000 Z
所以肯定有得分对象,但没有“滑块到这里!”文本显示在页面上。为什么这不起作用?
如果您需要更多信息,请告诉我们:)
答案 0 :(得分:1)
您需要指定<%= fields_for ...
您缺少=
标志。
尝试:
<%= f.fields_for :scores do |builder| %>
请参阅fields_for文档了解其使用情况。
虽然fields_for
无论使用simple_form都有效,但您也可以使用simple_fields_for
,因为您使用的是simple_form,如下所示:
<%= f.simple_fields_for :scores do |builder| %>