2012-11-13 108 views
0

我有一個表格搜索這樣的:選擇2無法顯示正確的選擇字段

filter http://s11.postimage.org/hdqtyhv03/filter.png

當我用select2select#search_topic,這成爲:

filter_error http://s13.postimage.org/gy9rrq0uv/filter_error.png

這是我的選擇2碼:

<% content_for :head do %> 
    <script type="text/javascript"> 
$(document).ready(function() { 
    $('#search_topic').select2(); 
}); 
    </script> 
<% end %> 

我的形式:

<%= form_tag({ controller: 'questions', action: 'search_filter' }, method: 'get', class: 'form-inline') do %> 
    <%= label_tag 'search_topic', 'Filter:', class: 'label_search' %> 
    <%= select_tag 'search_topic', options_from_collection_for_select(current_user.get_topics, :id, :name), :prompt => "Select topic" %> 
    <%= select_tag 'search_type', options_from_collection_for_select(@question_types, :id, :name), :prompt => "Select type question" %> 
    <%= submit_tag "Search", name: nil, class: 'btn' %> 
<% end %> 

我抄select2.jsselect2.css.scss(從selec2.css變更名稱)vendor/javascriptvendor/stylesheet

而且我在scss文件中將url('select2.png')更改爲image_url("select2.png")。我也複製select2.pngapp/assets/images。我有//= require select2。在application.css.scss我有@import "select2";。 我的代碼有什麼問題?

+0

您應該使用,而不是'select_tag'一個純文本輸入 - 'hidden_​​field_tag'。有關示例,請參閱官方文檔。 – melekes

+0

@antonk你是什麼意思純文本? – Thanh

+0

我的意思是,select2需要,而不是