diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0216d529..ba01aa99 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -64,15 +64,18 @@ class TagsController < ApplicationController @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_tags, - @open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -97,14 +100,18 @@ class TagsController < ApplicationController $related_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end # 删除已选tag @@ -116,14 +123,18 @@ class TagsController < ApplicationController $selected_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end def show_all diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b1ec023c..b0cc3ce6 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -370,4 +370,9 @@ module CoursesHelper end return homework_users end + + def get_courses_by_tag(tag_name) + Course.tagged_with(tag_name).order('updated_at desc') + end + end diff --git a/app/views/tags/_show_attachments.html.erb b/app/views/tags/_show_attachments.html.erb index 3484d135..43ed76e0 100644 --- a/app/views/tags/_show_attachments.html.erb +++ b/app/views/tags/_show_attachments.html.erb @@ -1,5 +1,5 @@
-<% if attachments_results.size < 0 %> +<% if attachments_results.try(:size).to_i < 0 %> <% else %>
<% attachments_results.each do |file| %> diff --git a/app/views/tags/_show_bids.html.erb b/app/views/tags/_show_bids.html.erb index 63f35173..e789979e 100644 --- a/app/views/tags/_show_bids.html.erb +++ b/app/views/tags/_show_bids.html.erb @@ -1,5 +1,5 @@
- <% if bids_results.size > 0 %> + <% if bids_results.try(:size).to_i > 0 %>
<% bids_results.each do |bid| %>

diff --git a/app/views/tags/_show_contests.html.erb b/app/views/tags/_show_contests.html.erb index 79c75652..bc2682fb 100644 --- a/app/views/tags/_show_contests.html.erb +++ b/app/views/tags/_show_contests.html.erb @@ -1,5 +1,5 @@

- <% if contests_results.size > 0 %> + <% if contests_results.try(:size).to_i > 0 %>
<% contests_results.each do |contest| %>

diff --git a/app/views/tags/_show_courses.html.erb b/app/views/tags/_show_courses.html.erb new file mode 100644 index 00000000..c99e3e22 --- /dev/null +++ b/app/views/tags/_show_courses.html.erb @@ -0,0 +1,14 @@ +

+ <% if courses_results.try(:size).to_i > 0 %> +
+ <% courses_results.each do |course| %> +

+ <%= l(:label_course) %>:<%= link_to "#{course.name}",course_path(course) %> +
+ <%= l(:label_new_course_description) %>:<%= course.description %> + <%= course.updated_at %> +

+
+ <% end %> + <% end %> +
diff --git a/app/views/tags/_show_forums.html.erb b/app/views/tags/_show_forums.html.erb index 009ec194..c6dd8a2e 100644 --- a/app/views/tags/_show_forums.html.erb +++ b/app/views/tags/_show_forums.html.erb @@ -1,5 +1,5 @@
- <% if forums_results.size > 0 %> + <% if forums_results.try(:size).to_i > 0 %>
<% forums_results.each do |forum| %>

diff --git a/app/views/tags/_show_issues.html.erb b/app/views/tags/_show_issues.html.erb index ab98cc35..399caf51 100644 --- a/app/views/tags/_show_issues.html.erb +++ b/app/views/tags/_show_issues.html.erb @@ -1,5 +1,5 @@

- <% if issues_results.size > 0 %> + <% if issues_results.try(:size).to_i > 0 %>
<% issues_results.each do |issue| %>

diff --git a/app/views/tags/_show_open_source_projects.html.erb b/app/views/tags/_show_open_source_projects.html.erb index 2c8bc637..8ea67f9a 100644 --- a/app/views/tags/_show_open_source_projects.html.erb +++ b/app/views/tags/_show_open_source_projects.html.erb @@ -1,5 +1,5 @@

-<% if projects_results.size > 0 %> +<% if projects_results.try(:size).to_i > 0 %>
<% projects_results.each do |prj| %>
diff --git a/app/views/tags/_show_projects.html.erb b/app/views/tags/_show_projects.html.erb index 6186b686..5dade07e 100644 --- a/app/views/tags/_show_projects.html.erb +++ b/app/views/tags/_show_projects.html.erb @@ -1,5 +1,5 @@
-<% if projects_results.size > 0 %> +<% if projects_results.try(:size).to_i > 0 %>
<% projects_results.each do |prj| %>
diff --git a/app/views/tags/_show_users.html.erb b/app/views/tags/_show_users.html.erb index 6818bdd9..d8b172ba 100644 --- a/app/views/tags/_show_users.html.erb +++ b/app/views/tags/_show_users.html.erb @@ -1,5 +1,5 @@
- <% if users_results.size > 0 %> + <% if users_results.try(:size).to_i > 0 %>
<% users_results.each do |user| %>

diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index 1ea452de..43048be5 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -26,6 +26,9 @@ <%#= l(:label_attachment)%> 开源项目:(<%= @results_count %>) <%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%> + <% when show_flag == '9'%> + <%= l(:label_course)%>(<%= @results_count %>) + <%= render :partial => "show_courses",:locals => {:courses_results => courses_results}%> <% else %> <%= l(:label_tags_all_objects)%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index c74721c3..a5cda994 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -23,7 +23,7 @@ <%= l(:label_user_plural) %>(<%= @users_tags_num %>) | <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) | <%= l(:field_filename)%>(<%= @attachments_tags_num %>) | - 开源项目(<%= @open_source_projects_num %>) + 开源项目(<%= @open_source_projects_num %>) | <%= l(:label_tags_contest)%>(<%= @contests_tags_num %>) |

@@ -37,6 +37,7 @@ :attachments_results=> @attachments_results, :contests_results => @contests_results, :open_source_projects_results => @open_source_projects_results, + :courses_results => @courses_results, :show_flag => @obj_flag} %>