Permalink
Browse files

added the photo shout

  • Loading branch information...
1 parent 2fe637a commit d62be818edd19022c7ba19a403f5df235d41b026 @drapergeek committed Mar 12, 2012
View
@@ -22,6 +22,7 @@ group :assets do
end
gem 'jquery-rails'
+gem 'paperclip'
group :test do
gem 'rspec-rails'
View
@@ -33,6 +33,7 @@ GEM
clearance (0.15.0)
diesel (~> 0.1.5)
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.2)
+ 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
- @shout = Shout.new
+ @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,8 @@
+class TextShoutsController < ApplicationController
+ def create
+ text_shout = TextShout.new(params[:text_shout])
+ shout = current_user.shouts.new(medium: text_shout)
+ shout.save
+ redirect_to dashboard_path, notice: "Shouted!"
+ end
+end
@@ -0,0 +1,6 @@
+class PhotoShout < ActiveRecord::Base
+ has_attached_file :photo, styles: {
+ thumb: "200x200"
+ }
+ has_one :shout, as: :medium
+end
View
@@ -1,5 +1,6 @@
class Shout < ActiveRecord::Base
belongs_to :user
+ belongs_to :medium, polymorphic: true
delegate :email, :to=>:user, :prefix=>true
View
@@ -1,2 +1,3 @@
class TextShout < ActiveRecord::Base
+ has_one :shout, as: :medium
end
@@ -1,9 +1,16 @@
<h1>Dashboard</h1>
Welcome <%= current_user.email %>! <%= link_to "Sign Out", sign_out_path, method: :delete %>
-<%= form_for @shout do |f| %>
+<%= form_for @text_shout do |f| %>
<%= f.text_field :body, placeholder: "Shout here" %>
<%= f.submit "Shout!" %>
<% end %>
+
+<strong>Add a photo shout</strong>
+<%= form_for @photo_shout do |f| %>
+ <%= f.file_field :photo %>
+ <%= f.submit "Shout!" %>
+<% end %>
+
<div id="shouts">
<%= render @shouts %>
</div>
@@ -8,7 +8,6 @@
</head>
<body>
<div class="content">
-
<% flash.each do |key, value| -%>
<div class="flash <%= key %>"><%= value %></div>
<% end -%>
@@ -0,0 +1 @@
+<%= link_to image_tag(photo_shout.photo.url(:thumb)), photo_shout.shout %> <%= time_ago_in_words(photo_shout.shout.created_at) %> ago
@@ -1,3 +1,3 @@
<%= content_tag_for(:div, shout) do %>
- <%= link_to shout.body, shout %> - <%= time_ago_in_words(shout.created_at) %> ago
+ <%= render shout.medium %>
<% end %>
@@ -1,8 +1,5 @@
<h2>Shout from <%= @shout.user_email %></h2>
-<div>
- <strong><%= @shout.body %></strong>
- <small><%= time_ago_in_words(@shout.created_at) %> ago</small>
-</div>
+<%= render @shout %>
<div>
<%= link_to "Dashboard", dashboard_path %>
</div>
@@ -0,0 +1 @@
+<%= link_to text_shout.body, text_shout.shout %> <%= time_ago_in_words(text_shout.shout.created_at) %> ago
@@ -33,7 +33,7 @@
config.assets.compress = false
# Expands the lines which load the assets
- config.assets.debug = true
+ #config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
View
@@ -1,5 +1,7 @@
Shouter::Application.routes.draw do
resource :dashboard, only: [:show]
- resources :shouts, only: [:show, :create]
+ resources :shouts, only: [:show]
+ resources :text_shouts, only: [:create]
+ resources :photo_shouts, only: [:create]
root to: "welcome#index"
end
@@ -16,9 +16,6 @@ def up
remove_column :shouts, :body
end
- def down
- add_column :shouts, :body, :text
- select_all("SELECT id, body FROM text_shouts").each do |text_shout|
update <<-SQL
UPDATE shouts
SET body="#{text_shout["body"]}"
@@ -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 => 20120312172656) 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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 d62be81

Please sign in to comment.