-1
在搜索頁面中,我有一個下拉列表,即從students
表填充。當我從下拉式和搜索按鈕點擊下拉列表中選擇的值丟失後的值,下面是下拉的代碼:無法將符號轉換爲整數f.select
<%= form_for :search, :url => { :method => :get, :action => :search } do |f| %>
<table>
<tr>
<td align="center">
<%= f.select(:Interest,options_from_collection_for_select(@students, "id", "student_mentor_subjects"), {},:id => "DDL_Students", :style => "width:160px;") %>
</td>
</tr>
<tr>
<td>
<div class="button">
<input type="submit" name="search" value="Search" class="buttonSearch">
</div>
</td>
</tr>
</table>
<% end %>
那麼谷歌之後,我在我的代碼把這個params[:search][:Interest] || @students.id
<%= form_for :search, :url => { :method => :get, :action => :search } do |f| %>
<table>
<tr>
<td align="center">
<%= f.select(:Interest,options_from_collection_for_select(@students, "id", "student_mentor_subjects", params[:search][:Interest] || @students.id), {},:id => "DDL_Students", :style => "width:160px;") %>
</td>
</tr>
<tr>
<td>
<div class="button">
<input type="submit" name="search" value="Search" class="buttonSearch">
</div>
</td>
</tr>
</table>
<% end %>
但是,通過使用上面的代碼我得到以下錯誤:
can't convert Symbol into Integer
下面
是「學生」表的模式:
id | student_mentor_subjects
1 | abc
2 | def
3 | ijk
我該如何解決這個問題。請建議我。謝謝
第一個我已經嘗試,但它不是給我的下拉列表中選擇的值成一個控制器頁面。第二個給我錯誤「不能將符號轉換爲整數」 – user88