From 575fc48ff05ec0770aa13f56cb637f5a88dfc260 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 25 Mar 2014 16:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=90=9C=E7=B4=A2=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 26 ++++++++++++++++++++++ app/views/welcome/_search_project.html.erb | 17 ++++++++++---- app/views/welcome/course.html.erb | 3 +-- app/views/welcome/index.html.erb | 1 - config/routes.rb | 6 +++-- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 7ca9b9669..a0e79f0f6 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -80,6 +80,32 @@ class WelcomeController < ApplicationController @student = User.student end + def search + search_condition = params[:q] + search_type = params[:search_type].to_sym unless search_condition.blank? + + respond_to do |format| + format.html{ + case search_type + when :projects + redirect_to projects_search_path(:name => search_condition, + :project_type => Project::ProjectType_project) + when :courses + redirect_to projects_search_path(:name => search_condition, + :project_type => Project::ProjectType_course) + when :users + redirect_to users_search_path(:name => search_condition) + when :users_teacher + redirect_to users_search_path(:name => search_condition, :role => :teacher) + when :users_student + redirect_to users_search_path(:name => search_condition, :role => :student) + else + redirect_to home_path, :alert => l(:label_sumbit_empty) + end + } + end + end + private # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 diff --git a/app/views/welcome/_search_project.html.erb b/app/views/welcome/_search_project.html.erb index 61770cace..ca7d151e8 100644 --- a/app/views/welcome/_search_project.html.erb +++ b/app/views/welcome/_search_project.html.erb @@ -1,7 +1,16 @@ -<%= form_tag(:controller => 'projects', :action => "search", :method => :get) do %> +<% + select_option = [] + (select_option << ['项目', 'projects']) if project_type == Project::ProjectType_project + (select_option << ['课程', 'courses']) if project_type == Project::ProjectType_course + select_option << ['用户', 'users'] + #select_option << ['教师', 'users_teacher'], + #select_option << ['学生', 'users_student'] +%> +<%= form_tag({controller: :welcome, action: :search }, method: :get) do %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index d7fafb49a..d0ad1fbcd 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -95,8 +95,7 @@ <%= l(:label_welcome_trustie) %> <%= l(:label_welcome_trustie_course) %> , <%= l(:label_welcome_trustie_course_description) %>
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index ad23a3b6b..490833a2b 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -96,7 +96,6 @@
diff --git a/config/routes.rb b/config/routes.rb index 41106c0a7..336d8dc51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,8 +56,8 @@ RedmineApp::Application.routes.draw do match 'git_usage/ch_usage', :controller => 'git_usage', :action => 'ch_usage', :via => :get, :as => 'ch_usage' match 'git_usage/en_usage', :controller => 'git_usage', :action => 'en_usage', :via => :get, :as => 'en_usage' #added by nie - match '/projects/search', :controller => 'projects', :action => 'search', :via => [:get, :post], :as => 'search' - match '/users/search', :controller => 'users', :action => 'search', :via => [:get, :post], :as => 'search' + match '/projects/search', :controller => 'projects', :action => 'search', :via => [:get, :post] + match '/users/search', :controller => 'users', :action => 'search', :via => [:get, :post] #end match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post] match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post] @@ -553,4 +553,6 @@ RedmineApp::Application.routes.draw do match 'tags/remove_tag',:to=>'tags#remove_tag',:as=>"remove_tag" match 'words/add_brief_introdution', :controller => 'words', :action => 'add_brief_introdution' + + get ':controller(/:action(/:id))' end