我目前有一个按几个选择框排序的表格。选择框可以正常工作并对表格进行排序/过滤,但是每当用户提交搜索时,页面都会刷新并且选择框会重置。我希望在搜索后保留所选项目,例如,如果您选择男性,然后点击 go,在页面刷新后,仍然选择男性。我目前已经成功实现了无限滚动,如果有帮助的话,我正在为我的框架使用 rails 3 和 twitter-bootstrap。
这是我的代码:
index.html.erb
<form class="form-inline"
<p>
<label class="radio">
<input type="radio" name="gender_search" value="M">M
</label>
<label class="radio">
<input type="radio" name="gender_search" value="F">F
</label>
<select name="state_search" class="span2">
<option value="">Select a State</option>
<option>----------------</option>
<option>LA</option>
<option>MS</option>
<option>TX</option>
</select>
<select name="city_search" class="span2">
<option value="">Select a City</option>
<option>----------------</option>
<option>Mandeville</option>
<option>Covington</option>
</select>
<button type="submit" class="btn">GO</button>
</p>
</form>
<table class="table table-striped table-bordered span8 table-condensed"
id="articles_table" >
<thead class="header">
<tr>
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th>Created_At</th>
</tr>
</thead>
<tbody>
<%= render @articles %>
</tbody>
_article.html.erb
<tr>
<td> <%= article_counter +1 %> </td>
<td> <%= article.Title %> </td>
<td> <%= article.Description %> </td>
<td> <%= article.Created_At %> </td>
</tr>
文章控制器.rb
def index
@articles = Article.state_search(params[:state_search]).gender_search(params[:gender_search]).city_search(params[:city_search]).page(params[:page]).limit(50).order('NTRP DESC', 'Last_Name ASC')
respond_to do |format|
format.html # index.html.erb
format.json { render json: @articles }
format.js
end
end