From 1f5c90185a7fccefd3af4256f32c11f3bb0bd5b8 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 11 Mar 2016 13:14:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E3=80=8A=E9=A1=B6?= =?UTF-8?q?=E9=83=A8=E6=90=9C=E7=B4=A2=E2=80=9C=E5=88=86=E6=9E=90=E2=80=9D?= =?UTF-8?q?=E6=8A=A5404=E9=94=99=E8=AF=AF=E3=80=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../welcome/_search_all_results.html.erb | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/views/welcome/_search_all_results.html.erb b/app/views/welcome/_search_all_results.html.erb index 4ed9fba33..51835106b 100644 --- a/app/views/welcome/_search_all_results.html.erb +++ b/app/views/welcome/_search_all_results.html.erb @@ -38,10 +38,19 @@
  • <%= item.try(:highlight).try(:description) ? item.highlight.description[0].html_safe : item.description %>
  • - 教师:<%= User.find(item.tea_id).realname %> - 授课时间:<%= item.time.to_s + item.term%> - 更新时间:<%= format_date(item.updated_at)%> - <%= User.find(item.tea_id).user_extensions.occupation.present? ? '单位:'+User.find(item.tea_id).user_extensions.occupation : ''%>
  • + <%= course_teacher = User.where("id = ?", item.tea_id).first if item.tea_id? %> + <% if course_teacher.nil? %> + 教师:无 + 授课时间:<%= item.time.to_s + item.term%> + 更新时间:<%= format_date(item.updated_at)%> + 单位:无 + <%= else %> + 教师:<%= User.find(item.tea_id).realname %> + 授课时间:<%= item.time.to_s + item.term%> + 更新时间:<%= format_date(item.updated_at)%> + <%= course_teacher.user_extensions.occupation.present? ? '单位:'+ course_teacher.user_extensions.occupation : ''%> + <% end %> +
    @@ -56,7 +65,8 @@
    <%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %>资源
    -
  • 发布者:<%= User.find(item.author_id).login%>(<%= User.find(item.author_id).realname%>) + <%= item_author = User.where("id = ?", item.author_id).first if item.author_id? %> +
  • 发布者:<%= item_author.nil? ? '无' : item_author.login%>(<%= item_author.realname unless item_author.nil? %>) 发布时间:<%= format_date(item.created_on)%> 下载次数:<%= item.downloads%>次 @@ -76,7 +86,8 @@
  • <%= item.try(:highlight).try(:description) ? item.highlight.description[0].html_safe : item.description%>
  • -
  • 管理人员:<%= item.user_id ? User.find(item.user_id).login : '无' %>更新时间:<%= date_format_local( Project.find(item.id).updated_on) %>
  • + <%= project_admin = User.where("id = ?", item.user_id).first if item.user_id? %> +
  • 管理人员:<%= project_admin.nil? ? '无' : project_admin.login %>更新时间:<%= date_format_local( Project.find(item.id).updated_on) %>
  • @@ -92,7 +103,8 @@
  • <%= item.try(:highlight).try(:content) ? item.highlight.content[0].html_safe : item.content.html_safe%>
  • -
  • 发帖人:<%= item.author_id ? User.find(item.author_id).login : '无' %>更新时间:<%= format_date( item.updated_at) %>
  • + <%= memo_author = User.where("id = ?", item.author_id).first if item.author_id? %> +
  • 发帖人:<%= memo_author.nil? ? '无' : memo_author.login %>更新时间:<%= format_date( item.updated_at) %>
  • From ce6d63ccafb6b970abdb5079334150a31571bb11 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Mon, 14 Mar 2016 10:24:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=87=8D=E6=9E=84user.find?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 11 +++ .../welcome/_search_all_results.html.erb | 80 ++++++++----------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index a74c20751..259b9d04e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1064,6 +1064,17 @@ class User < Principal anonymous_user end + # refactor User model find function, + # return anonymous user when can not find user id = user_id + def self.find user_id + user = User.new + begin + user = super + rescue + user = self.anonymous + end + user + end # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # This method is used in the SaltPasswords migration and is to be kept as is diff --git a/app/views/welcome/_search_all_results.html.erb b/app/views/welcome/_search_all_results.html.erb index 51835106b..a714f53d2 100644 --- a/app/views/welcome/_search_all_results.html.erb +++ b/app/views/welcome/_search_all_results.html.erb @@ -1,31 +1,31 @@ <% unless all_results.nil? || all_results.empty?%> -<% all_results.each do |item|%> - <% case item.type %> - <% when 'user'%> - - <% when 'attachment'%> + <% when 'attachment'%> - <% when 'project'%> + <% when 'project'%>
    @@ -103,14 +92,13 @@
  • <%= item.try(:highlight).try(:content) ? item.highlight.content[0].html_safe : item.content.html_safe%>
  • - <%= memo_author = User.where("id = ?", item.author_id).first if item.author_id? %> -
  • 发帖人:<%= memo_author.nil? ? '无' : memo_author.login %>更新时间:<%= format_date( item.updated_at) %>
  • +
  • 发帖人:<%= item.author_id ? User.find(item.author_id).login : '无' %>更新时间:<%= format_date( item.updated_at) %>
  • - <%end %> -<% end %> + <%end %> + <% end %>
    <%= paginate all_results,:params => {:controller => 'welcome', :action => 'search',:search_type=>'all'}%>
    From 2f5ce553e20834a4b44ee57c4d592fc6813d4ff7 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Mon, 14 Mar 2016 10:46:02 +0800 Subject: [PATCH 3/3] refactor user find --- app/models/user.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 259b9d04e..779566ea8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1066,14 +1066,13 @@ class User < Principal # refactor User model find function, # return anonymous user when can not find user id = user_id - def self.find user_id - user = User.new + def self.find (*args, &block) begin - user = super + super rescue - user = self.anonymous + self.anonymous end - user + # super end # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password))