优化代码

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

View File

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

View File

@ -1011,7 +1011,7 @@ class BidsController < ApplicationController
#验证是否显示课程
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
render_404
end
@ -1019,7 +1019,7 @@ class BidsController < ApplicationController
#验证是否显示竞赛
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
render_404
end

View File

@ -707,7 +707,7 @@ class ContestsController < ApplicationController
#验证是否显示竞赛
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
render_404
end

View File

@ -696,7 +696,7 @@ class CoursesController < ApplicationController
#验证是否显示课程
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
render_404
end

View File

@ -356,7 +356,7 @@ class HomeworkAttachController < ApplicationController
#验证是否显示课程
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
render_404
end

View File

@ -821,7 +821,7 @@ class UsersController < ApplicationController
#验证是否显示课程
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
render_404
end

View File

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

View File

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

View File

@ -189,7 +189,7 @@
</div>
<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;">
<%= textilizable @course.description %>

View File

@ -415,7 +415,7 @@ Redmine::MenuManager.map :course_menu do |menu|
end
Redmine::MenuManager.map :user_menu do |menu|
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_project, {:controller => 'users', :action => 'user_projects', :host => Setting.project_domain}
# menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} by huang