我有两种模式:自我评估和分数,其中自我评估has_many :scores
和accepts_nested_attributes_for :scores
。新的自我评估表可能有多达60个嵌套分数。我想要做的是对表单中的嵌套属性字段实现分页。
我试图实现它而没有运气。
控制器
def new
@self_assessment = SelfAssessment.new
@scores = @self_assessment.scores.paginate(:page => params[:page], :per_page => 10, :total_entries=> @self_assessment.scores.size)
end
视图
<%= form_for @self_assessment do |f| %>
<h2>At home...</h2>
<% Category.where(at_home: true).each do |category| %>
<h3><%= category.title %></h3>
<% Act.where(category_id: category.id).each do |act| %>
<%= f.fields_for :scores, Score.new do |builder| %>
<%= builder.hidden_field :self_assessment_id, value: @self_assessment.id %>
<%= builder.select(:rank, scales_for_select(act), prompt: "-Select-") %>
<%= act.name %><br>
<% end %>
<% end %>
<% end %>
<h2>At work...</h2>
<% Category.where(at_work: true).each do |category| %>
<h3><%= category.title %></h3>
<% Act.where(category_id: category.id).each do |act| %>
<%= f.fields_for :scores, Score.new do |builder| %>
<%= builder.hidden_field :self_assessment_id, value: @self_assessment.id %>
<%= builder.select(:rank, scales_for_select(act), prompt: "-Select-") %>
<%= act.name %><br>
<% end %>
<% end %>
<% end %>
<%= will_paginate @scores, :params => { :method => :post } %>
<%= f.submit "Submit" %>
答案 0 :(得分:1)