bigos
March 28, 2013, 8:04pm
1
I have problems with multiple file upload. I tried Paperclip with jQuery
file uplad plugin and get the error mentioned in the title. Files get
uploaded without problems, but I keep getting this embarrassing error.
Can somebody offer a solution to my problem or suggest alternative
solution
that can be implemented in 2 hours? My client is getting a bit uneasy
now.
I have tried everything I could think of and in the end I have modified
the
model following this advice:
opened 02:46PM - 03 Jun 11 UTC
closed 04:37AM - 06 Sep 12 UTC
I'm using basic example and keep getting "Empty file upload result" error althou… gh all files are uploading correctly.
I checked permissions for "files" and "thumbnails" folders - it's okay too (I tried 775 and 777).
Can somebody help me?
My code can be found at:
https://github.com/bigos/chrisb-images/blob/master/app/models/upload.rb
relevant bit in my model looks like this:
def to_jq_upload
{
:files => [
{
:name => upload_file_name,
:type => upload_content_type,
:size => upload_file_size,
:url => upload.url,
:delete_url => upload_path(self),
:delete_type => “DELETE”
}
]
}
end
bigos
March 29, 2013, 10:47am
2
On Thursday, 28 March 2013 19:03:48 UTC, Bigos wrote:
I have problems with multiple file upload. I tried Paperclip with jQuery
file uplad plugin and get the error mentioned in the title. Files get
uploaded without problems, but I keep getting this embarrassing error…
Fixed!!!
controller:
class PhotosController < ApplicationController
before_filter :require_admin, :except => [:index, :show]
# GET /photos
# GET /photos.json
def index
if params[:tag]
@photos = Photo.includes(:tags).where(:tags => {:name => params[:tag]}).order('photos.created_at DESC').paginate(:page => params[:page], :per_page => 12)
else
@photos = Photo.order('created_at DESC').paginate(:page => params[:page], :per_page => 12)
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @photos }
end
end
# GET /photos/1
This file has been truncated. show original
def create
@photo = Photo.new(params[:photo])
respond_to do |format|
if @photo.save
format.html { render :json => [@photo.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json { render json: {files: [@photo.to_jq_upload] }}
else
format.html { render action: "new" }
format.json { render json: @photo.errors, status:
:unprocessable_entity }
end
end
end
model:
class Photo < ActiveRecord::Base
attr_accessible :attachment_content_type, :attachment_file_name, :attachment_file_size, :attachment_updated_at, :attachment
has_many :taggings, :dependent => :destroy
has_many :tags, :through => :taggings
has_attached_file :attachment, :styles => {
:thumb => "100x150", :medium => "220x150"}
include Rails.application.routes.url_helpers
def tag_with!(tag_name)
#p "will try to tag it as #{tag_name}"
tag = Tag.where(name: tag_name).first
unless tag
tag = Tag.new(name: tag_name)
tag.save
end
tagging=Tagging.new(photo_id: self.id, tag_id: tag.id)
tagging.save
This file has been truncated. show original