diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0a6f15020..1318e40a5 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -38,41 +38,24 @@ class TagsController < ApplicationController @obj_id = params[:obj_id] @obj_flag = params[:object_flag] - @selected_tags = Array.new - @selected_tag_ids = Array.new - @selected_tag_objs = Array.new + @selected_tags = Array.new @related_tags = nil - @related_tag_ids = Array.new - @related_tag_objs = Array.new - if params[:q] - @tag = ActsAsTaggableOn::Tag.find(params[:q]) - @selected_tags << @tag.name - @selected_tag_ids << @tag.id.to_s - @selected_tag_objs << @tag + + if params[:q] + @selected_tags << params[:q] else @do_what = params[:do_what] - @tag = ActsAsTaggableOn::Tag.find(params[:tag]) - #@selected_tags = params[:current_selected_tags] - @selected_tag_ids = params[:current_selected_tags] - @selected_tag_ids = @selected_tag_ids.nil? ? Array.new : @selected_tag_ids - @selected_tag_ids.each do |t| - ta = ActsAsTaggableOn::Tag.find(t) - @selected_tags << ta.name - @selected_tag_objs << ta - end - #@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags + @tag = params[:tag] + @selected_tags = params[:current_selected_tags] + @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags case @do_what when '0' then - @selected_tags.delete @tag.name #数组中删除有多方式 可以改用shift,pop - @selected_tag_ids.delete @tag.id.to_s - @selected_tag_objs.delete @tag + @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop when '1' then # 判断是否已存在该tag 主要用来处理分页的情况 - unless @selected_tags.include? @tag.name - @selected_tags << @tag.name - @selected_tag_ids << @tag.id.to_s - @selected_tag_objs << @tag + unless @selected_tags.include? @tag + @selected_tags << @tag end end end @@ -92,7 +75,7 @@ class TagsController < ApplicationController @attachments_results, @contests_results, @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags,@selected_tag_ids) + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -102,13 +85,6 @@ class TagsController < ApplicationController # @tags.delete(i) # end @related_tags = @tags - @tag_objs = @obj.tags - @tag_objs.each do |t| - unless @selected_tags.include?(t.name) - @related_tag_ids << t.id.to_s - @related_tag_objs << t - end - end else return end @@ -186,8 +162,8 @@ class TagsController < ApplicationController if request.get? # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 - @tag_id = params[:tag_name] - @tag_name = (ActsAsTaggableOn::Tag.find(@tag_id)).name + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 @taggable_type = numbers_to_object_type(params[:taggable_type]) @@ -216,7 +192,7 @@ class TagsController < ApplicationController private # 这里用来刷新搜索结果的区域 # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 - def refresh_results(obj_id,obj_flag,selected_tags,selected_tag_ids = nil) + def refresh_results(obj_id,obj_flag,selected_tags) @users_results = nil @projects_results = nil @issues_results = nil @@ -234,36 +210,36 @@ class TagsController < ApplicationController case obj_flag when '1' then @obj = User.find_by_id(obj_id) - @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) when '2' then @obj = Project.find_by_id(obj_id) - @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) when '3' then @obj = Issue.find_by_id(obj_id) - @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) when '4' then - @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) @obj = Bid.find_by_id(obj_id) when '5' @obj = Forum.find_by_id(obj_id) - @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) when '6' @obj = Attachment.find_by_id(obj_id) # modifed by Long Jun # this is used to find the attachments that came from the same project and tagged with the same tag. #@result = get_attachments_by_project_tag(selected_tags, @obj) - @result = get_attachments_by_tag(selected_tags,selected_tag_ids) + @result = get_attachments_by_tag(selected_tags) @obj_pages, @attachments_results, @results_count = for_pagination(@result) when '7' @obj = Contest.find_by_id(obj_id) - @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags,selected_tag_ids)) + @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) when '8' @obj = OpenSourceProject.find_by_id(obj_id) - @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags,selected_tag_ids)) + @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) when '9' then @obj = Course.find_by_id(obj_id) - @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags,selected_tag_ids)) + @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) else @obj = nil end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 70a2e40e7..7ea49dad2 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -75,8 +75,8 @@ module AttachmentsHelper # this method is used to get all projects that tagged one tag # added by william - def get_attachments_by_tag(tag_name,selected_tag_ids = nil) - Attachment.tagged_with(tag_name,{},selected_tag_ids).order('created_on desc') + def get_attachments_by_tag(tag_name) + Attachment.tagged_with(tag_name).order('created_on desc') end # this method is used to get all attachments that from one project and tagged one tag diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 118e0ccb1..a5c25ecb5 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -35,8 +35,8 @@ module BidsHelper # this method is used to get all projects that tagged one tag # added by william - def get_bids_by_tag(tag_name,selected_tag_ids = nil) - Bid.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') + def get_bids_by_tag(tag_name) + Bid.tagged_with(tag_name).order('updated_on desc') end #added by huang diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index 983cf68bd..0bc3e5e73 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -35,8 +35,8 @@ module ContestsHelper # this method is used to get all projects that tagged one tag # added by william - def get_contests_by_tag(tag_name,selected_tag_ids = nil) - Contest.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') + def get_contests_by_tag(tag_name) + Contest.tagged_with(tag_name).order('updated_on desc') end #added by huang diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 77445532b..1afb94220 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -449,8 +449,8 @@ module CoursesHelper return homework_users end - def get_courses_by_tag(tag_name,selected_tag_ids = nil) - Course.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc') + def get_courses_by_tag(tag_name) + Course.tagged_with(tag_name).order('updated_at desc') end #课程实践年份下拉框 diff --git a/app/helpers/forums_helper.rb b/app/helpers/forums_helper.rb index 2d7b4bbb8..47a059e04 100644 --- a/app/helpers/forums_helper.rb +++ b/app/helpers/forums_helper.rb @@ -22,7 +22,7 @@ module ForumsHelper # this method is used to get all projects that tagged one tag # added by william - def get_forums_by_tag(tag_name,selected_tag_ids = nil) - Forum.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc') + def get_forums_by_tag(tag_name) + Forum.tagged_with(tag_name).order('updated_at desc') end end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index b5f49331f..637c92db3 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -382,8 +382,8 @@ module IssuesHelper # this method is used to get all projects that tagged one tag # added by william - def get_issues_by_tag(tag_name,selected_tag_ids = nil) - Issue.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') + def get_issues_by_tag(tag_name) + Issue.tagged_with(tag_name).order('updated_on desc') end end diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb index 8f7d31e05..dfc7cc8d0 100644 --- a/app/helpers/open_source_projects_helper.rb +++ b/app/helpers/open_source_projects_helper.rb @@ -31,8 +31,8 @@ module OpenSourceProjectsHelper s = content_tag('div', s, :class => 'user_tags') end - def get_open_source_projects_by_tag(tag_name,selected_tag_ids = nil) - OpenSourceProject.tagged_with(tag_name,{},selected_tag_ids).order('created_at desc') + def get_open_source_projects_by_tag(tag_name) + OpenSourceProject.tagged_with(tag_name).order('created_at desc') end def show_origin(url) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 3beed444d..5df3644ad 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -232,8 +232,8 @@ module ProjectsHelper # this method is used to get all projects that tagged one tag # added by william - def get_projects_by_tag(tag_name,selected_tag_ids = nil) - Project.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') + def get_projects_by_tag(tag_name) + Project.tagged_with(tag_name).order('updated_on desc') end # added by fq diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index ac3d5ad57..58935dd11 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -57,8 +57,8 @@ module UsersHelper # this method is used to get all projects that tagged one tag # added by william - def get_users_by_tag(tag_name,selected_tag_ids = nil) - User.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') + def get_users_by_tag(tag_name) + User.tagged_with(tag_name).order('updated_on desc') end # added by fq diff --git a/app/views/tags/_related_tags.html.erb b/app/views/tags/_related_tags.html.erb index 17e006da5..04b356598 100644 --- a/app/views/tags/_related_tags.html.erb +++ b/app/views/tags/_related_tags.html.erb @@ -5,14 +5,14 @@ <% i += 1 %>