fixes #693
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user