diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index f0ad448..0d2b687 100755 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -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 diff --git a/app/models/map.rb b/app/models/map.rb index 5efbfd0..3c95103 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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