Permalink
Browse files

Photo uploads.

  • Loading branch information...
1 parent 03aa2ca commit 7d99a4f0a98663ac24b995fdd3aeada3d04c7f42 @halogenandtoast halogenandtoast committed Mar 12, 2012
View
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
gem 'rails', '3.2.2'
gem 'clearance'
+gem 'paperclip'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
@@ -33,6 +33,7 @@ GEM
clearance (0.12.0)
diesel (~> 0.1.4)
rails (>= 3.0)
+ cocaine (0.2.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -64,6 +65,11 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
+ paperclip (2.5.0)
+ activerecord (>= 2.3.0)
+ activesupport (>= 2.3.2)
+ cocaine (>= 0.0.2)
+ mime-types
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -131,6 +137,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
factory_girl_rails
jquery-rails
+ paperclip
rails (= 3.2.2)
rspec-rails
sass-rails (~> 3.2.3)
@@ -1,6 +1,7 @@
class DashboardsController < ApplicationController
def show
@text_shout = TextShout.new
+ @photo_shout = PhotoShout.new
@shouts = current_user.shouts.current
end
end
@@ -0,0 +1,8 @@
+class PhotoShoutsController < ApplicationController
+ def create
+ photo_shout = PhotoShout.new(params[:photo_shout])
+ shout = current_user.shouts.new(medium: photo_shout)
+ shout.save
+ redirect_to dashboard_path, notice: "Shouted!"
+ end
+end
@@ -0,0 +1,4 @@
+class PhotoShout < ActiveRecord::Base
+ has_attached_file :photo
+ has_one :shout, as: :medium
+end
@@ -5,6 +5,10 @@ Welcome <%= current_user.email %> - <%= link_to "Sign out", sign_out_path, metho
<%= form.text_field :body, placeholder: "Shout here" %>
<%= form.submit "Shout!" %>
<% end %>
+<%= form_for(@photo_shout) do |form| %>
+ <%= form.file_field :photo %>
+ <%= form.submit "Shout!" %>
+<% end %>
<div id="shouts">
<%= render @shouts %>
@@ -0,0 +1 @@
+<%= link_to image_tag(photo_shout.photo), photo_shout.shout %>
View
@@ -3,4 +3,5 @@
resource :dashboard, only: [:show]
resources :shouts, only: [:show]
resources :text_shouts, only: [:create]
+ resources :photo_shouts, only: [:create]
end
@@ -0,0 +1,8 @@
+class CreatePhotoShouts < ActiveRecord::Migration
+ def change
+ create_table :photo_shouts do |t|
+
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,15 @@
+class AddAttachmentPhotoToPhotoShout < ActiveRecord::Migration
+ def self.up
+ add_column :photo_shouts, :photo_file_name, :string
+ add_column :photo_shouts, :photo_content_type, :string
+ add_column :photo_shouts, :photo_file_size, :integer
+ add_column :photo_shouts, :photo_updated_at, :datetime
+ end
+
+ def self.down
+ remove_column :photo_shouts, :photo_file_name
+ remove_column :photo_shouts, :photo_content_type
+ remove_column :photo_shouts, :photo_file_size
+ remove_column :photo_shouts, :photo_updated_at
+ end
+end
View
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120312172709) do
+ActiveRecord::Schema.define(:version => 20120312184732) do
+
+ create_table "photo_shouts", :force => true do |t|
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "photo_file_name"
+ t.string "photo_content_type"
+ t.integer "photo_file_size"
+ t.datetime "photo_updated_at"
+ end
create_table "shouts", :force => true do |t|
t.integer "user_id"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PhotoShoutTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 7d99a4f

Please sign in to comment.