学校列表添加了搜索功能

This commit is contained in:
Wen 2014-04-24 08:58:24 +08:00
parent 32294cf131
commit cc738edf2f
3 changed files with 40 additions and 5 deletions

View File

@ -31,4 +31,15 @@ class SchoolController < ApplicationController
render :text => options render :text => options
end end
def search_school
@school = School.where("province = ? AND name LIKE '%"+params[:key_word]+"%'", params[:province]);
options = ""
@school.each do |s|
options << "<li style = 'width: 33%; float: left'><a id=#{s.id} onclick='test(this.id)'>#{s.name}</a></li>"
end
render :text => options
end
end end

View File

@ -22,17 +22,38 @@
location.href = "welcome/index?course.trustie.net&school_id="+id; location.href = "welcome/index?course.trustie.net&school_id="+id;
} }
</script> </script>
<script type="text/javascript">
function ssearch(){
//alert($("#key_word").val());
value = $("#key_word").val();
province = $("#province").val();
//alert(province);
$.ajax({
type :"POST",
url :'/school/search_school/?key_word='+encodeURIComponent(value)+'&province='+province,
data :'text',
success: function(data){
$("#schoollist").html(data);
//$("#schoollist").html(data);
}
})
}
</script>
<div> <div>
<p> <p>
<a href="welcome/index?course.trustie.net&school_id=0">全部学校</a> <a href="welcome/index?course.trustie.net&school_id=0">全部学校</a>
</p> </p>
<p> <ul>
请选择省份:<%= select_tag "province", <li style="width: 40%; float: left">请选择省份:<%= select_tag "province",
options_from_collection_for_select(School.find_by_sql("select distinct province from schools"), :province, :province), options_from_collection_for_select(School.find_by_sql("select distinct province from schools"), :province, :province),
:onclick => "get_school(this.value)" %> :onclick => "get_school(this.value)" %></li>
</p> <li style="width: 50%; float: left"><input type="text" id="key_word" name="key_word" />
<input type="button" class="enterprise" value="搜索" onclick="ssearch()"></li>
</ul>
</div> </div>
<div> <div>
<ul id="schoollist" style="line-height: 25px"> <ul id="schoollist" style="line-height: 25px">

View File

@ -585,6 +585,9 @@ RedmineApp::Application.routes.draw do
post 'school/get_schoollist/:province', :to => 'school#get_schoollist' post 'school/get_schoollist/:province', :to => 'school#get_schoollist'
get 'school/get_schoollist/:province', :to => 'school#get_schoollist' get 'school/get_schoollist/:province', :to => 'school#get_schoollist'
post 'school/search_school/', :to => 'school#search_school'
get 'school/search_school/', :to => 'school#search_school'
######added by nie ######added by nie
match 'tags/show_projects_tags',:to => 'tags#show_projects_tags' match 'tags/show_projects_tags',:to => 'tags#show_projects_tags'
########### added by liuping ########### added by liuping