It's been waaay too long since I last committed. Eesh.
This commit is contained in:
@@ -1,44 +1,43 @@
|
||||
class MashesController < ApplicationController
|
||||
# GET /mashes
|
||||
# GET /mashes.xml
|
||||
|
||||
def index
|
||||
@mashes = Mash.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @mashes }
|
||||
format.html
|
||||
format.xml { render :xml => @mashes }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mashes/1
|
||||
# GET /mashes/1.xml
|
||||
def show
|
||||
@mash = Mash.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @mash }
|
||||
format.html
|
||||
format.xml { render :xml => @mash }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mashes/new
|
||||
# GET /mashes/new.xml
|
||||
def new
|
||||
@mash = Mash.new
|
||||
map_a, map_b = Map.rand(2)
|
||||
|
||||
@mash = Mash.new(
|
||||
:requestor => request.remote_ip,
|
||||
:map_a => map_a.id,
|
||||
:map_b => map_b.id,
|
||||
:winner => 0
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @mash }
|
||||
format.html
|
||||
format.xml { render :xml => @mash }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mashes/1/edit
|
||||
def edit
|
||||
@mash = Mash.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /mashes
|
||||
# POST /mashes.xml
|
||||
def create
|
||||
@mash = Mash.new(params[:mash])
|
||||
|
||||
@@ -46,16 +45,14 @@ class MashesController < ApplicationController
|
||||
if @mash.save
|
||||
flash[:notice] = 'Mash was successfully created.'
|
||||
format.html { redirect_to(@mash) }
|
||||
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
||||
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /mashes/1
|
||||
# PUT /mashes/1.xml
|
||||
def update
|
||||
@mash = Mash.find(params[:id])
|
||||
|
||||
@@ -63,23 +60,21 @@ class MashesController < ApplicationController
|
||||
if @mash.update_attributes(params[:mash])
|
||||
flash[:notice] = 'Mash was successfully updated.'
|
||||
format.html { redirect_to(@mash) }
|
||||
format.xml { head :ok }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /mashes/1
|
||||
# DELETE /mashes/1.xml
|
||||
def destroy
|
||||
@mash = Mash.find(params[:id])
|
||||
@mash.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(mashes_url) }
|
||||
format.xml { head :ok }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,5 +1,25 @@
|
||||
require 'fastercsv'
|
||||
|
||||
|
||||
class Map < ActiveRecord::Base
|
||||
def self.from_city_name(city_name)
|
||||
self.find_or_initialize_by_name(city_name).save!
|
||||
end
|
||||
|
||||
def self.rand(count = 2)
|
||||
self.find(:all, :order => 'RANDOM()', :limit => count)
|
||||
end
|
||||
|
||||
def self.import(csv_filename)
|
||||
FasterCSV.parse(open(csv_filename), :headers => true,
|
||||
:header_converters => [:downcase, :symbol]).each do |row|
|
||||
map = self.find_or_initialize_by_name(
|
||||
"#{row[:city]}, #{row[:country]}"
|
||||
)
|
||||
map.save
|
||||
if block_given?
|
||||
yield map
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user