我正在尝试使用will_paginate来显示我想要显示的项目列表。 有一个表单,其中包含下拉选项以按状态获取对象。 这是我的控制器
def list
@person = Person.find_by_id(session[:person_id])
params[:status] = params[:redirect_status] if params.has_key?('redirect_status')
@statuses = Peptide.statuses
@status = 'Not Ordered'
@status = params[:status] if params[:status] != nil || params[:status] == ''
@peptides = Peptide.find(:all, :conditions => ['status = ?', @status]).paginate(:per_page => 30, :page => params[:page])
if Peptide.count.zero?
flash[:notice] = "There are not any peptides entered"
redirect_to :action => 'new'
end#if zero
end
这是在视图中
<form action="/peptide/create_spreadsheet_of_not_ordered" enctype="multipart/form-data" method="post">
<table class="sortable" cellpading="5" cellspacing="2" width="100">
<tr class= "header-line">
<th>SS</th>
<th>Status</th>
<th>Peptide</th>
<th>Gene</th>
<th>Submitter</th>
<th>Created</th>
<th>Updated</th>
<th>Sequence</th>
<th>Modification</th>
<th>Vendor</th>
</tr>
<% for @peptide in @peptides.reverse %>
<tr valign = "top" class= "<%= cycle('color_one', 'color_two') %>">
<!--an error here during development likely indicates that the people table has not be repopulated or
that no submitter primer is present for a primer-->
<td sorttable_customkey = 0 > <%=check_box_tag "box[]", @peptide.id %>
<td><%= @peptide.status%></td>
<td class><%= link_to @peptide.name, :action => :report, :id => @peptide.id %></td>
<td><%= gene_links(@peptide.genes) rescue 'Error'%></td>
<td><%= @peptide.submitter.name rescue "" %></td>
<td <%= sorttable_customkey_from_date(@peptide.created_at)%> >
<%= @peptide.created_at.strftime("%b %d %Y") rescue "Unknown"%>
</td>
<td <%= sorttable_customkey_from_date(@peptide.updated_at)%> >
<%= @peptide.updated_at.strftime("%b %d %Y") rescue "Unknown"%>
</td>
<td><%= @peptide.sequence%></td>
<td><%= @peptide.modifications%></td>
<td><%= @peptide.vendor%></td>
<%= buttons() %>
</tr>
<%end%>
<%= will_paginate @peptides %>
</table>
<br>
<%= submit_tag "Create Spreadsheet"%>
默认列表按订购状态分组。
然而,当我选择任何其他状态并提交表单时,分页链接会将我带回默认状态。 请帮我解决这个问题。 感谢
答案 0 :(得分:0)
在没有看到视图的情况下,听起来您需要将当前params
作为参数添加到其他状态的链接...
<强>更新强>
尝试将params添加到您的状态链接:
<%= link_to @peptide.name, peptide_path(@peptide, params), :action => :report, :id => @peptide.id %>
documentation就在这里。