diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 22:20:24 -0400 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 22:20:24 -0400 |
commit | 91fee659eadaf6bcc4d063fd5645950da1250896 (patch) | |
tree | bf1df15fd055199fc07d971623bfd6632dc3dee4 /app | |
parent | 0d42079611ed2aeacd71b926580fdc3b943cf1ba (diff) |
A few bug fixes, and a bunch of code that almost works.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/tournament.rb | 47 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 23 |
2 files changed, 49 insertions, 21 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e408cfe..0b55cb6 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,9 +1,56 @@ class Tournament < ActiveRecord::Base belongs_to :game has_many :matches + has_many :preferences_raw, class_name: "TournamentPreference" has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" + def preferences + @preferences ||= Preferences.new(self) + end + def preferences=(pref) + pref.each do |key, value| + value = false if valuedd == "0" + preferences[key] = value + end + end + + class Preferences + def initialize(tournament) + @tournament = tournament + end + + def [](preference) + p = @tournament.preferences_raw.find_by_name(preference) + if p.nil? + return nil + else + return p.value + end + end + + def []=(preference, value) + p = @tournament.preferences_raw.find_by_name(preference) + if p.nil? + # TODO: create it + else + p.value = value + end + end + + def keys + @tournament.preferences_raw.all.collect { |x| x.name } + end + + def method_missing(name, *args) + if name.to_s.ends_with?('=') + self[name.to_s.sub(/=$/, '').to_sym] = args.first + else + return self[name.to_sym] + end + end + end + def open? return true end diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index 3661077..b66acb0 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -2,7 +2,7 @@ <%= render "common/error_messages", :target => @tournament %> <%= f.hidden_field(:game_id) %> - <% @game = Game.find_by(params[:game]) %> + <% @game = Game.find(params[:game]) %> <% @tournament.attributes.each do |name, value| %> <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") or (name == "set_rounds") %> <% next %> @@ -17,24 +17,5 @@ </p> <% end %> - <% @settings = GameSetting.find_by(params[:game_id]) %> - <% unless @settings %> - <br> - <br> - <br> - <br> - <br> - <br> - <br> - <br> - <% end %> - <% @settings.each do |setting| %> - <p> - <%= f.label setting.name %><br> - <% #eventually display by non-generic input method %> - <%= f.select :setting options_from_collection_for_select([setting.description, ""].append setting.type_opt.split(',')) %> - </p> - <% end %> - - <%= f.submit %> + <%= f.submit %> <% end %> |