Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68b0372
commit 2467f63
Showing
31 changed files
with
4,192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Admin::UploadsController < ApplicationController | ||
|
||
def index | ||
@uploads = Upload.all | ||
render :json => @uploads.collect { |p| p.to_jq_upload }.to_json | ||
end | ||
|
||
def create | ||
@upload = Upload.new(params[:upload]) | ||
if @upload.save | ||
render :json => [@upload.to_jq_upload].to_json | ||
else | ||
render :json => [{:error => "custom_failure"}], :status => 304 | ||
end | ||
end | ||
|
||
def destroy | ||
@upload = Upload.find(params[:id]) | ||
@upload.destroy | ||
render :json => true | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Admin::AssetsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Archive < Upload | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Audio < Upload | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Document < Upload | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Image < Upload | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Upload < ActiveRecord::Base | ||
belongs_to :attachable, :polymorphic => true | ||
|
||
# Paperclip | ||
has_attached_file :data, :styles => { :thumb => "80x80>", :small => "150x150>", :medium => "300x300>", :large => "650x650>" }, | ||
:url => "/uploads/:id/:style/:basename.:extension", | ||
:path => ":rails_root/public/uploads/:id/:style/:basename.:extension" | ||
|
||
# if attachment is not an image prevents the resize post processor from running | ||
before_post_process :is_image? | ||
|
||
# Paperclip Validations | ||
validates_attachment_presence :data | ||
|
||
# Used by before_post_process validation to skip images post processing if not an image | ||
def is_image? | ||
["image/jpeg", "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp"].include?(self.data_content_type) | ||
end | ||
|
||
def to_jq_upload | ||
{ | ||
"name" => read_attribute(:data_file_name), | ||
"size" => data_file_size, | ||
"url" => data.url, | ||
"thumbnail_url" => data.url(:thumb), | ||
"delete_url" => "/admin/uploads/#{id}", | ||
"delete_type" => "DELETE" | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Video < Upload | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CreateUploads < ActiveRecord::Migration | ||
def self.up | ||
create_table :uploads do |t| | ||
t.string :data_content_type | ||
t.string :data_file_name | ||
t.integer :data_file_size | ||
t.datetime :data_updated_at | ||
t.string :type | ||
t.integer :attachable_id | ||
t.string :attachable_type | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :uploads | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.