Updated Map.save to save package/build/map to database

refs #16
This commit is contained in:
2012-04-26 11:34:39 -04:00
parent 93bc1f943e
commit b3c7b164b4
2 changed files with 32 additions and 7 deletions

View File

@@ -32,8 +32,8 @@ class MapsController < ApplicationController
end
def uploadFile
post = Map.save(params[:upload])
session[:uploadSuccess] = true
post = Map.save(params)
session[:uploadSuccess] = post
redirect_to(:back)
end

View File

@@ -25,13 +25,38 @@ class Map < ActiveRecord::Base
require 'digest/sha1'
def self.save(upload)
validates_presence_of :map, :package, :build
def self.save(p)
map = Map.new
if !p[:package].to_s.empty?
map.package = p[:package]
end
if !p[:build].to_s.empty?
map.build = p[:build]
end
upload = p[:upload]
name = upload['datafile'].original_filename
directory = "public/data"
sha1 = Digest::SHA1.hexdigest name
# create the file path
path = File.join(directory, sha1)
# write the file
File.open(path, "wb") { |f| f.write(upload['datafile'].read) }
map.map = sha1
if map.save
# create the file path
path = File.join(directory, sha1)
# write the file
File.open(path, "wb") { |f| f.write(upload['datafile'].read) }
else
return false
end
end
def getMap()
end
end