From 8cec84dca7ca8658c870eabf8d505eaf52bf51df Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Mon, 3 Nov 2014 15:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0<=E5=85=AC=E5=85=B1=E8=B4=B4?= =?UTF-8?q?=E5=90=A7=20=E6=97=A0=E5=B8=96=E5=AD=90=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20=E5=BB=BA=E8=AE=AE=E5=A2=9E=E5=8A=A0>?= =?UTF-8?q?=EF=BC=8C<=E7=AE=A1=E7=90=86=E5=91=98=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=B4=B4=E5=90=A7=E7=9A=84=E7=83=AD=E5=BA=A6?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=B0=86=E8=B4=B4=E5=90=A7=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: alan <547533434@qq.com> --- app/controllers/forums_controller.rb | 4 ++- app/models/forum.rb | 4 ++- app/views/forums/_form.html.erb | 12 ++++++++ app/views/forums/_forum_list.html.erb | 11 +++++-- app/views/forums/index.html.erb | 3 +- app/views/memos/_form.html.erb | 2 +- config/locales/zh.yml | 1 + config/routes.rb | 1 + .../20141030071656_add_data_for_school.rb | 26 ----------------- .../20141103015148_add_column_to_forums.rb | 6 ++++ ...41103032156_set_sticky_locked_for_forum.rb | 9 ++++++ ...20141103065703_add_data_for_school_name.rb | 29 +++++++++++++++++++ db/schema.rb | 4 ++- 13 files changed, 78 insertions(+), 34 deletions(-) delete mode 100644 db/migrate/20141030071656_add_data_for_school.rb create mode 100644 db/migrate/20141103015148_add_column_to_forums.rb create mode 100644 db/migrate/20141103032156_set_sticky_locked_for_forum.rb create mode 100644 db/migrate/20141103065703_add_data_for_school_name.rb diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index d5fc1770c..cd51d2e58 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -52,7 +52,7 @@ class ForumsController < ApplicationController def index @offset, @limit = api_offset_and_limit({:limit => 10}) - @forums_all = Forum.where('1=1') + @forums_all = Forum.reorder("sticky DESC") @forums_count = @forums_all.count @forums_pages = Paginator.new @forums_count, @limit, params['page'] @@ -208,6 +208,8 @@ class ForumsController < ApplicationController end end + + private diff --git a/app/models/forum.rb b/app/models/forum.rb index 24b5b15e0..e0592723e 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -8,7 +8,9 @@ class Forum < ActiveRecord::Base 'topic_count', 'memo_count', 'last_memo_id', - 'creator_id' + 'creator_id', + 'sticky', + 'locked' validates_presence_of :name, :creator_id, :description validates_length_of :name, maximum: 50 #validates_length_of :description, maximum: 255 diff --git a/app/views/forums/_form.html.erb b/app/views/forums/_form.html.erb index 556238732..9b3519b05 100644 --- a/app/views/forums/_form.html.erb +++ b/app/views/forums/_form.html.erb @@ -17,6 +17,18 @@
<%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share' %>
+
+ <% if User.current.logged? && User.current.admin? %> + <% if @forum.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> + <%= label_tag 'message_sticky', l(:label_board_sticky) %> + <% end %> + <% if @forum.safe_attribute? 'locked' %> + <%= f.check_box :locked %> + <%= label_tag 'message_locked', l(:label_board_locked) %> + <% end %> + <% end %> +

diff --git a/app/views/forums/_forum_list.html.erb b/app/views/forums/_forum_list.html.erb index 9d0eba923..874dc355f 100644 --- a/app/views/forums/_forum_list.html.erb +++ b/app/views/forums/_forum_list.html.erb @@ -7,9 +7,14 @@ <%= forum.creator.nil? ? (link_to image_tag(url_to_avatar(forum.creator), :class => "avatar")) : (link_to image_tag(url_to_avatar(forum.creator), :class => "avatar"), user_path(forum.creator)) %>

-

<%= link_to h(forum.name), forum_path(forum) %>

-

<%= textAreailizable forum.description%>

-

<%= authoring forum.created_at, forum.creator %>

+ + + + +
+

<%= link_to h(forum.name), forum_path(forum) %>

<%= textAreailizable forum.description%>

<%= authoring forum.created_at, forum.creator %>

+
<%= link_to (forum.memo_count), forum_path(forum) %><%= link_to (forum.topic_count), forum_path(forum) %>
回答帖子
diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index fa6e74ccd..31d00891e 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -11,7 +11,8 @@ <% if User.current.logged? %> <%= link_to( l(:label_forum_new), new_forum_path, :class => 'icon icon-add') %> - <% end %> + <% end %> +