現在、いくつかの選択ボックスでソートされたテーブルがあります。選択ボックスは正しく機能し、テーブルを並べ替え/フィルター処理しますが、ユーザーが検索を送信するたびに、ページが更新され、選択ボックスがリセットされます。選択したアイテムを検索後に固定したいので、たとえば、[男性] を選択して [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>
article_controller.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