This commit is contained in:
albert
2013-03-02 21:23:37 -05:00
parent b3ab52e889
commit 3a262d0d50
3 changed files with 17 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ class UploadsController < ApplicationController
def create
@upload = Upload.create(params[:upload].merge(:server => Socket.gethostname))
@upload.process!
@upload.process! if @upload.errors.empty?
respond_with(@upload)
end

View File

@@ -12,11 +12,24 @@ class Upload < ActiveRecord::Base
before_create :convert_cgi_file
after_destroy :delete_temp_file
validate :uploader_is_not_limited
validate :file_or_source_is_present
module ValidationMethods
def uploader_is_not_limited
if !uploader.can_upload?
raise Error.new(uploader.upload_limited_reason)
self.errors.add(:uploader, uploader.upload_limited_reason)
return false
else
return true
end
end
def file_or_source_is_present
if file.blank? && source.blank?
self.errors.add(:base, "Must choose file or specify source")
return false
else
return true
end
end

View File

@@ -10,6 +10,8 @@
<%= render "post", :post => @post %>
<%= render "sources/info", :source => @source %>
<%= error_messages_for "upload" %>
<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => 'form'}) do |f| %>
<div class="input">
<%= f.label :file %>