diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 82aadf229..c68eda474 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -1,6 +1,6 @@ class ContestsController < ApplicationController - before_filter :find_contest, :only => [:show] + before_filter :find_contest, :only => [:show, :settings] before_filter :is_logged, :only => [:index, :new, :create] layout "base_contests" @@ -54,4 +54,8 @@ class ContestsController < ApplicationController redirect_to signin_path unless User.current.logged? end + def settings + + end + end diff --git a/app/models/contest.rb b/app/models/contest.rb index 4a8d35262..59f7bbbe1 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -84,4 +84,22 @@ class Contest < ActiveRecord::Base def act_as_contest_activity self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.id) end + + # 延迟生成邀请码 + def invite_code + return generate_invite_code + end + + # 生成邀请码 + # 如果已有改邀请码,则重新生成 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_invite_code + code = read_attribute(:invite_code) + if !code || code.size < 4 + code = CODES.sample(4).join + return generate_invite_code if Project.where(invite_code: code).present? + update_attribute(:invite_code, code) + end + code + end end diff --git a/app/views/contests/settings.html.erb b/app/views/contests/settings.html.erb new file mode 100644 index 000000000..f55fa6ef6 --- /dev/null +++ b/app/views/contests/settings.html.erb @@ -0,0 +1,214 @@ +
- <%= link_to @contest.user.try(:show_name), user_path(@contest.user), :class => "sy_cgrey" %> > - <%= link_to @contest.name, contest_path(@contest), :class => "sy_cgrey" %> > - <%= link_to "配置", settings_contest_path(@contest), :class => "sy_cgrey" %> -
- <% if is_contest_manager?(User.current.id, @contest.id) %> - <%= render :partial => "contests/mamager_setting" %> - <% end %> - - - -+ <%= link_to @contest.user.try(:show_name), user_path(@contest.user), :class => "sy_cgrey" %> > + <%= link_to @contest.name, contest_path(@contest), :class => "sy_cgrey" %> > + <%= link_to "配置", settings_contest_path(@contest), :class => "sy_cgrey" %> +
+ <% if is_contest_manager?(User.current.id, @contest.id) %> + <%= render :partial => "contests/mamager_setting" %> <% end %> + + + ++ 管理员:<%= contest_managers(@contest).count %> + 评委:<%= contest_judges(@contest).count %> + 参赛者:<%= contest_contestants(@contest).count %> +
+- 管理员:<%= contest_managers(@contest).count %> - 评委:<%= contest_judges(@contest).count %> - 参赛者:<%= contest_contestants(@contest).count %> -
+