Permalink
Browse files

Basic uploading support (in progress)

  • Loading branch information...
1 parent 3334046 commit f03148d2c7b9e93383cf2c97b7edd4d8859237a2 @jbbarth jbbarth committed Jan 30, 2009
View
@@ -4,3 +4,4 @@ tmp/**/*
db/*.sqlite3
db/*.db
nbproject/*
+public/assets/*
@@ -4,6 +4,10 @@ def index
@assets = Asset.find(:all)
end
+ def new
+ @asset = Asset.new
+ end
+
def create
@asset = Asset.new(params[:asset])
if @asset.save
@@ -13,9 +17,4 @@ def create
render :action => :new
end
end
-
- def upload
- post = Asset.save(params[:asset])
- render :text => "File has been uploaded successfully"
- end
end
@@ -67,7 +67,11 @@ def user_authorize
unless valid
# we didn't find a author... send them to the login page
session[:came_from] = nil
- #session[:came_from] = request.parameters if !$no_session_actions.index(params[:action])
+ if !$no_session_actions.index(params[:action])
+ req = request.parameters.dup
+ req.delete("asset")
+ session[:came_from] = req
+ end
flash[:notice] = 'Please log in'
redirect_to Site.full_url + '/login' and return false
end
@@ -80,7 +84,11 @@ def update_checker
misc_class = Admin::MiscController.new
# track where they came from, in case they turn this off
session[:came_from] = nil
- session[:came_from] = request.parameters if !$no_session_actions.index(params[:action])
+ if !$no_session_actions.index(params[:action])
+ req = request.parameters.dup
+ req.delete("asset")
+ session[:came_from] = req
+ end
# get the last update record
last_update = Update.find(1)
# how long ago was this check?
View
@@ -1,7 +1,11 @@
class Asset < ActiveRecord::Base
- def self.save(upload)
- directory = "public/files"
- path = File.join(directory, upload['file'].original_filename)
- File.open(path, "wb") { |f| f.write(upload['file'].read) }
- end
+
+ has_attachment :content_type => :image,
+ :storage => :file_system,
+ :max_size => 5.megabytes,
+ :resize_to => '320x200>',
+ :thumbnails => { :thumb => '100x100>' }
+
+ validates_as_attachment
+
end
@@ -9,7 +9,7 @@
<label for="asset"><b>File</b></label>
</td>
<td class="fields">
- <%= file_field "asset", "file" %>
+ <%= file_field "asset", "uploaded_data" %>
</td>
</tr>
<!--[eoform:tag]-->
@@ -5,7 +5,9 @@
<br/>
</div>
-<% form_tag(Site.full_url + '/admin/assets/upload', :multipart => true) do %>
+<%= error_messages_for :mugshot %>
+
+<% form_tag(Site.full_url + '/admin/assets/create', :multipart => true) do %>
<%= render :partial => 'admin/assets/form' %>
<div class="submit_area">
<%= submit_tag 'Upload the file', :class => 'submit' %> or
@@ -1,18 +1,18 @@
class CreateAssets < ActiveRecord::Migration
def self.up
-# create_table :assets do |t|
-# t.integer :parent_id
-# t.string :content_type
-# t.string :filename
-# t.string :thumbnail
-# t.integer :size
-# t.integer :width
-# t.integer :height
-# t.timestamps
-# end
+ create_table :assets do |t|
+ t.integer :parent_id
+ t.string :content_type
+ t.string :filename
+ t.string :thumbnail
+ t.integer :size
+ t.integer :width
+ t.integer :height
+ t.timestamps
+ end
end
def self.down
-# drop_table :assets
+ drop_table :assets
end
end
View
@@ -11,6 +11,18 @@
ActiveRecord::Schema.define(:version => 30) do
+ create_table "assets", :force => true do |t|
+ t.integer "parent_id"
+ t.string "content_type"
+ t.string "filename"
+ t.string "thumbnail"
+ t.integer "size"
+ t.integer "width"
+ t.integer "height"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "authors", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "modified_at", :null => false
View
No changes.
View
Deleted file not rendered

0 comments on commit f03148d

Please sign in to comment.