Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Forked from JamesZoft/TournamentEntry.rb
Last active December 16, 2015 09:39
Show Gist options
  • Save tpendragon/5414304 to your computer and use it in GitHub Desktop.
Save tpendragon/5414304 to your computer and use it in GitHub Desktop.
Enter new tournament information
<hr>
<%= form_for @tournamentEntry do |f| -%>
Entry requirements: <%= f.text_field :entry_reqs %><br />
Links: <%= f.text_field :links %> <br />
Format: <%= f.text_field :format %> <br />
Future: <%= f.radio_button(:status, :future) %> <br />
Past: <%= f.radio_button(:status, :past) %> <br />
Ongoing: <%= f.radio_button(:status, :ongoing) %> <br />
Location: <%= f.text_field :location %> <br />
Name: <%= f.text_field :name %> <br />
Prizes: <%= f.text_field :prizes %> <br />
Sponsor: <%= f.text_field :sponsor %> <br />
<%= f.submit %>
<% end -%>
<hr>
Display all tournaments
<% TournamentEntry.find_each do |entry| %>
<%= entry.name %> <%= entry.inspect %> <br />
<%end %>
FypDbeditForm::Application.routes.draw do
resources :match_entries, :controller => :match_entry
resources :tournament_entries, :controller => :tournament_entry
end
class TournamentEntry < ActiveRecord::Base
attr_accessible :entry_reqs, :format, :future, :links, :location, :name, :ongoing, :past, :prizes, :sponsor :status
# attr_accessor :status
def status
if !self.future.blank?
return "future"
elsif !self.ongoing.blank?
return "ongoing"
elsif !self.past.blank?
return "past"
end
end
def status=(val)
self.past = nil
self.future = nil
self.ongoing = nil
if(val == "ongoing")
self.ongoing = true
elsif(val == "past")
self.past = true
elsif(val == "future")
self.future = true
end
end
end
class TournamentEntryController < ApplicationController
def new
@tournamentEntry = TournamentEntry.new
end
def create
@tournamentEntry = TournamentEntry.new(params[:tournamentEntry])
if @tournamentEntry.save
redirect_to new_tournament_entry_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment