From 6d058940ec04b8c6a7e5afd66e2a62170bc05439 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 23 Apr 2015 11:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E8=AF=BE=E7=A8=8B=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E6=97=B6=E8=87=AA=E5=8A=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=85=B6=E8=AE=A8=E8=AE=BA=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 22 ++++++++++++++-------- app/views/layouts/base_courses.html.erb | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index bdbbb8e37..a301d270d 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -42,12 +42,19 @@ class BoardsController < ApplicationController elsif @course if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @boards = @course.boards.includes(:last_message => :author).all - @boards = [] << @boards[0] if @boards.any? + if @course.boards.empty? + @board = @course.boards.build + @board.name = " #{l(:label_borad_course) }" + @board.description = @course.name.to_s + @board.project_id = -1 + if @board.save + @boards = @course.boards.includes(:last_message => :author).all + end + end if @boards.size == 1 - @board = @boards.first - show and return + @board = @course.boards.first end - render :layout => 'base_courses' + show and return else render_403 end @@ -65,7 +72,7 @@ class BoardsController < ApplicationController 'replies' => "#{Message.table_name}.replies_count", 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" - @topic_count = @board.topics.count + @topic_count = @board ? @board.topics.count : 0 if @project @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] @topics = @board.topics. @@ -77,14 +84,13 @@ class BoardsController < ApplicationController preload(:author, {:last_reply => :author}). all elsif @course - board_topics = @board.topics. - reorder("#{Message.table_name}.sticky DESC"). + board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC"). includes(:last_reply). # limit(@topic_pages.per_page). # offset(@topic_pages.offset). order(sort_clause). preload(:author, {:last_reply => :author}). - all + all : [] @topics = paginateHelper board_topics,10 end diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index dc384834c..6993b6554 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -132,8 +132,8 @@