优化代码

This commit is contained in:
z9hang 2014-10-16 11:09:45 +08:00
parent 7729a2739f
commit 57776d67c5
11 changed files with 25 additions and 33 deletions

View File

@ -144,9 +144,9 @@ class AdminController < ApplicationController
#首页定制 #首页定制
def first_page_made def first_page_made
if request.get? if request.get?
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
elsif request.post? elsif request.post?
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
@first_page.web_title = params[:web_title] @first_page.web_title = params[:web_title]
@first_page.description = params[:first_page][:description] @first_page.description = params[:first_page][:description]
#@first_page.title = params[:title] #@first_page.title = params[:title]
@ -179,11 +179,11 @@ class AdminController < ApplicationController
def course_page_made def course_page_made
if request.get? if request.get?
@course_page = FirstPage.where("page_type = 'course'").first @course_page = FirstPage.find_by_page_type('course')
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
elsif request.post? elsif request.post?
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
@course_page = FirstPage.where("page_type = 'course'").first @course_page = FirstPage.find_by_page_type('course')
@first_page.web_title = params[:web_title] @first_page.web_title = params[:web_title]
@course_page.web_title = params[:web_title] @course_page.web_title = params[:web_title]
@course_page.title = params[:course_title] @course_page.title = params[:course_title]
@ -215,12 +215,12 @@ class AdminController < ApplicationController
def contest_page_made def contest_page_made
if request.get? if request.get?
@contest_page = FirstPage.where("page_type = 'contest'").first @contest_page = FirstPage.find_by_page_type('contest')
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
@notification = ContestNotification.first; @notification = ContestNotification.first;
elsif request.post? elsif request.post?
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
@contest_page = FirstPage.where("page_type = 'contest'").first @contest_page = FirstPage.find_by_page_type('contest')
@notification = ContestNotification.first; @notification = ContestNotification.first;
@first_page.web_title = params[:web_title] @first_page.web_title = params[:web_title]
@contest_page.web_title = params[:web_title] @contest_page.web_title = params[:web_title]
@ -255,10 +255,10 @@ class AdminController < ApplicationController
def web_footer_made def web_footer_made
if request.get? if request.get?
@organizer = WebFooterOranizer.first @organizer = WebFooterOranizer.first
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
#@notification = ContestNotification.all.first; #@notification = ContestNotification.all.first;
elsif request.post? elsif request.post?
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
@first_page.web_title = params[:web_title] @first_page.web_title = params[:web_title]
@organizer = WebFooterOranizer.first @organizer = WebFooterOranizer.first
if @organizer.nil? if @organizer.nil?

View File

@ -754,7 +754,7 @@ class ApplicationController < ActionController::Base
#查找首页相关信息 #查找首页相关信息
def find_first_page def find_first_page
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.nil? if @first_page.nil?
@first_page = FirstPage.new @first_page = FirstPage.new
@first_page.page_type = 'project' @first_page.page_type = 'project'

View File

@ -1011,7 +1011,7 @@ class BidsController < ApplicationController
#验证是否显示课程 #验证是否显示课程
def can_show_course def can_show_course
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_course == 2 if @first_page.show_course == 2
render_404 render_404
end end
@ -1019,7 +1019,7 @@ class BidsController < ApplicationController
#验证是否显示竞赛 #验证是否显示竞赛
def can_show_contest def can_show_contest
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_contest == 2 if @first_page.show_contest == 2
render_404 render_404
end end

View File

@ -707,7 +707,7 @@ class ContestsController < ApplicationController
#验证是否显示竞赛 #验证是否显示竞赛
def can_show_contest def can_show_contest
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_contest == 2 if @first_page.show_contest == 2
render_404 render_404
end end

View File

@ -696,7 +696,7 @@ class CoursesController < ApplicationController
#验证是否显示课程 #验证是否显示课程
def can_show_course def can_show_course
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_course == 2 if @first_page.show_course == 2
render_404 render_404
end end

View File

@ -356,7 +356,7 @@ class HomeworkAttachController < ApplicationController
#验证是否显示课程 #验证是否显示课程
def can_show_course def can_show_course
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_course == 2 if @first_page.show_course == 2
render_404 render_404
end end

View File

@ -821,7 +821,7 @@ class UsersController < ApplicationController
#验证是否显示课程 #验证是否显示课程
def can_show_course def can_show_course
@first_page = FirstPage.where("page_type = 'project'").first @first_page = FirstPage.find_by_page_type('project')
if @first_page.show_course == 2 if @first_page.show_course == 2
render_404 render_404
end end

View File

@ -25,8 +25,6 @@ class WelcomeController < ApplicationController
before_filter :entry_select, :only => [:index] before_filter :entry_select, :only => [:index]
def index def index
#@first_page = FirstPage.where("page_type = 'project'").first
#@show_course = @first_page.show_course
if @first_page.nil? || @first_page.sort_type.nil? if @first_page.nil? || @first_page.sort_type.nil?
@projects = find_miracle_project(10, 3,"score desc") @projects = find_miracle_project(10, 3,"score desc")
else else
@ -61,12 +59,7 @@ class WelcomeController < ApplicationController
end end
def course def course
@course_page = FirstPage.where("page_type = 'course'").first @course_page = FirstPage.find_by_page_type('course')
#if params[:school_id]
# @school_id = params[:school_id]
#elsif User.current.logged? && User.current.user_extensions.try(:school)
# @school_id = User.current.user_extensions.school.try(:id)
#end
@school_id = params[:school_id] || User.current.user_extensions.school.try(:id) @school_id = params[:school_id] || User.current.user_extensions.school.try(:id)
@logoLink ||= logolink() @logoLink ||= logolink()
end end
@ -74,7 +67,7 @@ class WelcomeController < ApplicationController
def logolink() def logolink()
@course_page = FirstPage.where("page_type = 'course'").first @course_page = FirstPage.find_by_page_type('course')
logo = get_avatar?(@course_page) logo = get_avatar?(@course_page)
id = params[:school_id] id = params[:school_id]
logo_link = "" logo_link = ""
@ -110,7 +103,7 @@ class WelcomeController < ApplicationController
def contest def contest
@contest_page = FirstPage.where("page_type = 'contest'").first @contest_page = FirstPage.find_by_page_type('contest')
@contest_notifications = Contestnotification.order("created_at desc").limit(5) @contest_notifications = Contestnotification.order("created_at desc").limit(5)
end end
@ -150,7 +143,6 @@ class WelcomeController < ApplicationController
private private
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
def entry_select def entry_select
#@first_page = FirstPage.where("page_type = 'project'").first
url = request.original_url.gsub('/','') url = request.original_url.gsub('/','')
if url.include?(Setting.host_course.gsub('/','')) if url.include?(Setting.host_course.gsub('/',''))
if @first_page.show_course == 1 if @first_page.show_course == 1

View File

@ -652,7 +652,7 @@ module ApplicationHelper
if(args == ["/"]) if(args == ["/"])
args = [] args = []
end end
first_page = FirstPage.where("page_type = 'project'").first first_page = FirstPage.find_by_page_type('project')
if args.empty? if args.empty?
title = @html_title || [] title = @html_title || []
title << @project.name if @project title << @project.name if @project

View File

@ -189,7 +189,7 @@
</div> </div>
<div style="padding-bottom: 8px"> <div style="padding-bottom: 8px">
<% if @course.description && @course.description.lstrip.rstrip.size>0 %> <% if @course.description && !@course.description.blank? %>
<div class="font_lighter_sidebar" style="word-break:break-all; word-wrap:break-word;"> <div class="font_lighter_sidebar" style="word-break:break-all; word-wrap:break-word;">
<%= textilizable @course.description %> <%= textilizable @course.description %>

View File

@ -415,7 +415,7 @@ Redmine::MenuManager.map :course_menu do |menu|
end end
Redmine::MenuManager.map :user_menu do |menu| Redmine::MenuManager.map :user_menu do |menu|
menu.push :activity, {:controller => 'users', :action => 'show', :host => Setting.user_domain } menu.push :activity, {:controller => 'users', :action => 'show', :host => Setting.user_domain }
menu.push :user_course, {:controller => 'users', :action => 'user_courses'},:if => Proc.new {|c| FirstPage.where("page_type = 'project'").first.show_course != 2} menu.push :user_course, {:controller => 'users', :action => 'user_courses'},:if => Proc.new {|c| FirstPage.find_by_page_type('project').show_course != 2}
#menu.push :user_homework, {:controller => 'users', :action => 'user_homeworks'} by huang #menu.push :user_homework, {:controller => 'users', :action => 'user_homeworks'} by huang
menu.push :user_project, {:controller => 'users', :action => 'user_projects', :host => Setting.project_domain} menu.push :user_project, {:controller => 'users', :action => 'user_projects', :host => Setting.project_domain}
# menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} by huang # menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} by huang