class SchoolController < ApplicationController before_filter :require_admin, :only => :upload_logo def upload uploaded_io = params[:logo] school_id = 0 schools = School.where("name = ?", params[:school]) schools.each do |s| school_id = s.id end unless uploaded_io.nil? File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file| file.write(uploaded_io.read) end s1 = School.find(school_id) s1.logo_link = '/images/school/'+school_id.to_s+'.png' s1.save end end def upload_logo end def index end def get_province @provinces = School.find_by_sql("select distinct province from schools") options = "" @provinces.each do |p| options << "" end @school = School.all options_s = "" @school.each do |s| #options << "" options_s << "
  • #{s.name}
  • " end res = Hash.new res[:text] = options res[:text_s] = options_s render :json => res end def get_options @school = School.where("province = ?", params[:province]) p = params[:province] ##@school = School.all options = "" @school.each do |s| #options << "" options << "
  • #{s.name}
  • " end render :text => options end def get_schoollist @school = School.where("province = ?", params[:province]) options = "" @school.each do |s| options << "
  • #{s.name}
  • " end render :text => options end def search_school if params[:province].nil? or params[:province] == "0" @school = School.where("name LIKE '%"+params[:key_word]+"%'"); else @school = School.where("province = ? AND name LIKE '%"+params[:key_word]+"%'", params[:province]); end options = "" @school.each do |s| options << "
  • #{s.name}
  • " end render :text => options end end