Sha256: e295e20e3d48c117fb6e9cb77d5a3ee9d7e02462c18294e5de10a5226d1abe6a

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

require_dependency "educode_sales/application_controller"

module EducodeSales
  class HomeController < ApplicationController
    def index
    end

    def statistics
    end

    def no_permission
    end

    def search_users
      @users = User.where("lastname like :q OR login like :q OR phone like :q or mail like :q", q: "%#{params[:q]}%").limit(20)
    end

    def search
      if params[:type] == 'department'
       
       @data = Department.joins(:school).where("schools.name like :q", q: "%#{params[:q]}%").limit(20)
        unless @data.present?
          @data = Department.where("name like ?", "%#{params[:q]}%").limit(20)
        end
      elsif params[:type] == "school"
        data = School.where("name like ? ", "%#{params[:q]}%").limit(20)
      end
    end

    def search_teacher
      @data = Teacher.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20)
      user_ids = @data.pluck(:user_id).compact.uniq
      @data += User.joins(:user_extension).where.not(id: user_ids).where("identity='teacher'", user_ids).where("lastname like ?", "%#{params[:q]}%").limit(20)
    end

    def search_edu_teacher
      @data = User.joins(:user_extension).where("identity='teacher'").where("lastname like ? OR phone like ? OR mail like ?", "%#{params[:q]}%", "%#{params[:q]}%", "%#{params[:q]}%").limit(20)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
educode_sales-0.2.8 app/controllers/educode_sales/home_controller.rb
educode_sales-0.2.7 app/controllers/educode_sales/home_controller.rb
educode_sales-0.2.6 app/controllers/educode_sales/home_controller.rb
educode_sales-0.2.5 app/controllers/educode_sales/home_controller.rb