From 46b508be2b546df078385ff7fe5091f0df6cc64b Mon Sep 17 00:00:00 2001 From: yanxd Date: Sat, 8 Mar 2014 11:08:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=20=E8=AE=BA=E5=9D=9B?= =?UTF-8?q?=E5=8F=91=E5=B8=96=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 1 + app/controllers/memos_controller.rb | 1 + app/helpers/welcome_helper.rb | 18 ++++++++++++++++++ app/views/memos/show.html.erb | 8 ++++++++ app/views/welcome/course.html.erb | 2 +- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index a47bbdafc..be1a331e0 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -5,6 +5,7 @@ class ForumsController < ApplicationController before_filter :find_forum_if_available before_filter :authenticate_user_edit, :only => [:edit, :update] before_filter :authenticate_user_destroy, :only => [:destroy] + before_filter :require_login, :only => [:new, :create] helper :sort include SortHelper diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index ab8df148d..49e6c1764 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -5,6 +5,7 @@ class MemosController < ApplicationController before_filter :find_memo, :except => [:new, :create, :preview] before_filter :authenticate_user_edit, :only => [:edit, :update] before_filter :authenticate_user_destroy, :only => [:destroy] + before_filter :require_login, :only => [:new, :create] helper :attachments include AttachmentsHelper diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 52bc3383e..034bf7fe1 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -22,6 +22,24 @@ module WelcomeHelper include CoursesHelper include ProjectsHelper + # 前略·天国の首页君/Earth has been unable stop to welcomePage's. + # sum - 要搜索的项目数量 + # max_rate - 新项目所占所有项目的比重,10分制 + # + # Examples + # + # find_miracle_course(10, 7) + # # => 前7个项目为新课程,后面三个是参与人数最多的 + # + # Returns project&courses array + def find_miracle_course(sum=10, max_rate=7) + max = sum*(max_rate.to_f/10) + c1 = find_new_course(sum).to_a.dup + c2 = find_all_hot_course(sum).to_a.dup + c2 = c2 - c1 + (c1.take(max)+c2).take(sum) + end + def find_new_course limit=15 Project.visible.joins(:course_extra).where("#{Project.table_name}.project_type = ? ", 1).order("courses.time DESC, #{Project.table_name}.created_on DESC").limit(limit).all end diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index 6c5aae172..eca6cc95b 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -96,6 +96,14 @@ +<% if User.current.login? %>
<%= render :partial => 'reply_box' %>
+<% else %> +
+ <%= l(:label_user_login_tips) %> + <%= link_to l(:label_user_login_new), signin_path %> +
+
+<% end %> diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index 9ae0a42ec..7ec029b97 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -110,7 +110,7 @@ <%= link_to "更多>>", {:controller => 'projects', :action => 'course', :project_type => 1, :project_sort_type => 1}, :target => "_blank" %>