省份与学校的级联完成!

This commit is contained in:
Wen 2014-04-15 16:57:19 +08:00
parent 4da8b4e5f6
commit 37bb5341e4
3 changed files with 606 additions and 567 deletions

View File

@ -1,2 +1,15 @@
class SchoolController < ApplicationController class SchoolController < ApplicationController
def get_options
@school = School.where("province = ?", params[:province])
p = params[:province]
##@school = School.all
options = ""
@school.each do |s|
options << "<option value=#{s.name}>#{s.name}</option>"
end
render :text => options
end
end end

View File

@ -1,3 +1,20 @@
<script type="text/javascript">
function get_options(value){
$.ajax({
type :"POST",
url :'/school/get_options/'+encodeURIComponent(value),
data :'text',
success: function(data){
$("#occupation").html(data);
}
}
)
}
</script>
<div class="contextual" style="padding-right: 10px;"> <div class="contextual" style="padding-right: 10px;">
<%= link_to(l(:button_change_password), {:action => 'password'}, :class => 'icon icon-passwd') if @user.change_password_allowed? %> <%= link_to(l(:button_change_password), {:action => 'password'}, :class => 'icon icon-passwd') if @user.change_password_allowed? %>
<%= call_hook(:view_my_account_contextual, :user => @user)%> <%= call_hook(:view_my_account_contextual, :user => @user)%>
@ -72,9 +89,9 @@
<!-- added by Wen --> <!-- added by Wen -->
<p style="width:357px;padding-left: 26px;"> <p style="width:357px;padding-left: 26px;">
<%= l(:field_occupation) %>&nbsp;<select name='province'><%= options_from_collection_for_select(School.find_by_sql("select distinct province from schools"), :province, :province) %></select> <%= l(:field_occupation) %>&nbsp;<%= select_tag "province", options_from_collection_for_select(School.find_by_sql("select distinct province from schools"), :province, :province), :onchange => "get_options(this.value)" %>
<%= select_tag 'occupation', options_from_collection_for_select(School.all, :name, :name) %> <%= select_tag "occupation" %>
</p> </p>

View File

@ -548,6 +548,15 @@ RedmineApp::Application.routes.draw do
match 'calls/:id', :controller => 'bids', :action => 'show', :as => 'respond' match 'calls/:id', :controller => 'bids', :action => 'show', :as => 'respond'
match 'contest', :controller => 'bids', :action => 'contest', :as => 'contest' match 'contest', :controller => 'bids', :action => 'contest', :as => 'contest'
########################
##added by wen##########
#######confusing########
post 'school/get_options/:province', :to => 'school#get_options'
get 'school/get_options/:province', :to => 'school#get_options'
######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