Permalink
Browse files

Basic Paperclip + S3 stuff now works

  • Loading branch information...
1 parent 69c0d8f commit 58c09fa5abb10c780a39a7f4ff7b4442a6680d18 @joerichsen committed Oct 11, 2010
View
@@ -2,3 +2,4 @@
db/*.sqlite3
log/*.log
tmp/**/*
+config/s3.yml
View
@@ -1,7 +1,9 @@
source 'http://rubygems.org'
+# Rails and db
gem 'rails', '3.0.0'
-
gem 'sqlite3-ruby', :require => 'sqlite3'
+# Paperclip stuff
gem 'paperclip', '2.3.4'
+gem 'aws-s3', '0.6.2'
View
@@ -30,6 +30,10 @@ GEM
activesupport (3.0.0)
arel (1.0.1)
activesupport (~> 3.0.0)
+ aws-s3 (0.6.2)
+ builder
+ mime-types
+ xml-simple
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
@@ -67,11 +71,13 @@ GEM
treetop (1.4.8)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
+ xml-simple (1.0.12)
PLATFORMS
ruby
DEPENDENCIES
+ aws-s3 (= 0.6.2)
paperclip (= 2.3.4)
rails (= 3.0.0)
sqlite3-ruby
@@ -0,0 +1,21 @@
+class UsersController < ApplicationController
+
+ def index
+ @users = User.all
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+
+ if @user.save
+ redirect_to users_path, :notice => 'User was successfully created'
+ else
+ render new_user_path
+ end
+ end
+
+end
View
@@ -0,0 +1,13 @@
+class User < ActiveRecord::Base
+
+ has_attached_file :avatar,
+ :styles => {
+ :thumbnail => "100x100",
+ :large => "300x300"
+ },
+ :storage => :s3,
+ :s3_credentials => "#{Rails.root}/config/s3.yml",
+ :path => ":attachment/:id/:style/:basename.:extension",
+ :bucket => 'transloadit-paperclip-example'
+
+end
@@ -0,0 +1,8 @@
+<h1>Users</h1>
+<ul>
+ <% for user in @users %>
+ <li> <%= image_tag user.avatar.url %></li>
+ <% end %>
+</ul>
+
+<%= link_to 'create new user', new_user_path %>
@@ -0,0 +1,12 @@
+<h1>Create new user</h1>
+
+<% form_for(@user, :html => { :multipart => true }) do |f| %>
+ <p>
+ <%= f.label :avatar %><br />
+ <%= f.file_field :avatar %>
+ </p>
+ <p>
+ <%= f.submit %> or <%= link_to 'cancel', users_path %>
+ </p>
+<% end %>
+
View
@@ -1,58 +1,4 @@
TransloaditPaperclipExample::Application.routes.draw do
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => "welcome#index"
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ resources :users
+ root :to => "users#index"
end
View
@@ -0,0 +1,2 @@
+access_key_id: YOURSECRETACCESSID
+secret_access_key: YOUR-secRE/TACCe\ssKEy
@@ -0,0 +1,17 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+
+ t.string :avatar_file_name
+ t.string :avatar_content_type
+ t.integer :avatar_file_size
+ t.datetime :avatar_updated_at
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
@@ -0,0 +1,24 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20101011072228) do
+
+ create_table "users", :force => true do |t|
+ t.string "avatar_file_name"
+ t.string "avatar_content_type"
+ t.integer "avatar_file_size"
+ t.datetime "avatar_updated_at"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
Oops, something went wrong.

0 comments on commit 58c09fa

Please sign in to comment.