diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index b4de06fb6..62f860a96 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -51,7 +51,10 @@ class MemosController < ApplicationController @memo_new = @memo.dup @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 - @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) + unless @memo.new_record? + @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) + end + page = params[:page] if params[:r] && page.nil? @@ -68,10 +71,14 @@ class MemosController < ApplicationController limit(@reply_pages.per_page). offset(@reply_pages.offset). all + if @memo.new_record? + format.html { redirect_to back_url, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + else + format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + # format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end - format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } - # format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } - format.json { render json: @memo.errors, status: :unprocessable_entity } end end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index f16dbd97f..7c60e2dc3 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -32,7 +32,7 @@ class WelcomeController < ApplicationController def course if params[:school_id] @school_id = params[:school_id] - else + elsif User.current.logged? && User.current.user_extensions.school @school_id = User.current.user_extensions.school.id end @logoLink ||= logolink() diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 0054b003f..1004a49ad 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -233,8 +233,13 @@ module WelcomeHelper def find_all_new_hot_course limit = 9 ,school_id = 0 #sort_project_by_hot_rails 1, 'course_ac_para DESC', limit time_now = Time.new.strftime("%Y"); + if school_id courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> ?", school_id).order("course_ac_para DESC").limit(limit).all + else + courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL + ").order("course_ac_para DESC").limit(limit).all + end courses end diff --git a/app/models/memo.rb b/app/models/memo.rb index 1e857a223..feb10dec9 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -3,9 +3,9 @@ class Memo < ActiveRecord::Base belongs_to :forum belongs_to :author, :class_name => "User", :foreign_key => 'author_id' - validates_presence_of :author_id, :forum_id, :subject + validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 - validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } + #validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } validates_length_of :subject, maximum: 50 validates_length_of :content, maximum: 3072 validate :cannot_reply_to_locked_topic, :on => :create diff --git a/app/models/user.rb b/app/models/user.rb index 6138f9b56..257681cb5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,7 +164,7 @@ class User < Principal # Prevents unauthorized assignments attr_protected :login, :admin, :password, :password_confirmation, :hashed_password - LOGIN_LENGTH_LIMIT = 60 + LOGIN_LENGTH_LIMIT = 25 MAIL_LENGTH_LIMIT = 60 validates_presence_of :login, :firstname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index 9a25d9dbf..e79cc12cf 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -3,26 +3,25 @@