Skip to content

Commit

Permalink
Change from file_column to paperclip
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Peychich committed Oct 6, 2009
1 parent a48e659 commit 7734427
Show file tree
Hide file tree
Showing 87 changed files with 5,212 additions and 2,919 deletions.
2 changes: 1 addition & 1 deletion app/helpers/profiles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ProfilesHelper
def icon profile, size = :small, img_opts = {}
return "" if profile.nil?
img_opts = {:title => profile.full_name, :alt => profile.full_name, :class => size}.merge(img_opts)
link_to(avatar_tag(profile, {:size => size, :file_column_version => size }, img_opts), profile_path(profile)) rescue ''
link_to(avatar_tag(profile, {:size => size, :paperclip_style => size}, img_opts), profile_path(profile)) rescue ''
end

def location_link profile = @p
Expand Down
19 changes: 11 additions & 8 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ class Photo < ActiveRecord::Base

belongs_to :profile

validates_presence_of :image, :profile_id
has_attached_file :image, :styles => { :square => "50x50#", :small => "175x250>"}

validates_attachment_presence :image
validates_presence_of :profile_id
attr_immutable :id, :profile_id

def after_create
feed_item = FeedItem.create(:item => self)
([profile] + profile.friends + profile.followers).each{ |p| p.feed_items << feed_item }
end

file_column :image, :magick => {
:versions => {
:square => {:crop => "1:1", :size => "50x50", :name => "square"},
:small => "175x250>"
}
}
# file_column :image, :magick => {
# :versions => {
# :square => {:crop => "1:1", :size => "50x50", :name => "square"},
# :small => "175x250>"
# }
# }

end
16 changes: 9 additions & 7 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ class Profile < ActiveRecord::Base
set_property :min_prefix_len => 3, :morphology => false
end

file_column :icon, :magick => {
:versions => {
:big => {:crop => "1:1", :size => "150x150", :name => "big"},
:medium => {:crop => "1:1", :size => "100x100", :name => "medium"},
:small => {:crop => "1:1", :size => "50x50", :name => "small"}
}
}
has_attached_file :icon, :styles => { :big => "150x150#", :medium => "100x100#", :small => "50x50#" }, :default_url => "/avatar_default_:style.png"
#
# file_column :icon, :magick => {
# :versions => {
# :big => {:crop => "1:1", :size => "150x150", :name => "big"},
# :medium => {:crop => "1:1", :size => "100x100", :name => "medium"},
# :small => {:crop => "1:1", :size => "50x50", :name => "small"}
# }
# }

cattr_accessor :featured_profile
@@featured_profile = {:date=>Date.today-4, :profile=>nil}
Expand Down
2 changes: 1 addition & 1 deletion app/views/photos/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h2>Upload A Photo</h2>

<% less_form_for [@p,@photo], :html => {:multipart=>true} do |f| %>
<%= f.wrap(:image, :label => 'Photo: '){file_column_field "photo", "image", :size => 15} %>
<%= f.wrap(:image, :label => 'Photo: '){f.file_field :image, :size => 15} %>
<%= f.text_area :caption %>

<div class="row button">
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<h2><%= "Upload Icon:" %></h2>

<%= p.front :icon, :label => 'Upload your Icon' %>
<%= file_column_field( "profile", "icon", :size => 15)%>
<%= p.file_field :icon, :size => 15%>
<div class="clear"></div>
<% unless @p.icon.blank? %>
<div id="avatar_edit">
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/avatar_sources.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'avatar'
require 'avatar/source/file_column_source'
require 'avatar/source/paperclip_source'
require 'avatar/source/source_chain'
require 'avatar/source/static_url_source'
require 'avatar/source/wrapper/rails_asset_source_wrapper'
Expand All @@ -24,7 +24,7 @@
)

chain = Avatar::Source::SourceChain.new
chain << Avatar::Source::FileColumnSource.new(:icon)
chain << Avatar::Source::PaperclipSource.new(:icon)
chain << SizedGravatarSource.new(default, :email)

Avatar::source = chain
4 changes: 2 additions & 2 deletions config/initializers/file_column_settings.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FileColumn::ClassMethods::DEFAULT_OPTIONS[:root_path] = File.join(RAILS_ROOT, "public", 'system')
FileColumn::ClassMethods::DEFAULT_OPTIONS[:web_root] = 'system/'
# FileColumn::ClassMethods::DEFAULT_OPTIONS[:root_path] = File.join(RAILS_ROOT, "public", 'system')
# FileColumn::ClassMethods::DEFAULT_OPTIONS[:web_root] = 'system/'
90 changes: 90 additions & 0 deletions db/migrate/20091006171847_move_to_paperclip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
class MoveToPaperclip < ActiveRecord::Migration
def self.up
# Profiles
add_column :profiles, :icon_file_name, :string
add_column :profiles, :icon_content_type, :string
add_column :profiles, :icon_file_size, :integer
add_column :profiles, :icon_updated_at, :datetime

Profile.find_each do |profile|
next unless profile.old_icon
profile.icon = File.new(profile.old_icon)
profile.save
end

remove_column :profiles, :icon

# Photos
add_column :photos, :image_file_name, :string
add_column :photos, :image_content_type, :string
add_column :photos, :image_file_size, :integer
add_column :photos, :image_updated_at, :datetime

Photo.find_each do |photo|
next unless photo.old_image
photo.image = File.new(profile.old_image)
photo.save
end

remove_column :photos, :image
end

def self.down
# Profiles
add_column :profiles, :icon, :string

Profile.find_each do |profile|
next unless profile.icon
profile.old_icon = File.new(profile.icon.path)
profile.save
end

remove_column :profiles, :icon_updated_at
remove_column :profiles, :icon_file_size
remove_column :profiles, :icon_content_type
remove_column :profiles, :icon_file_name

# Photos
add_column :photos, :image, :string

Photo.find_each do |photo|
next unless photo.image
photo.old_image = File.new(photo.image.path)
photo.save
end

remove_column :photos, :image_updated_at
remove_column :photos, :image_file_size
remove_column :photos, :image_content_type
remove_column :photos, :image_file_name
end
end


# just for redundancy. we want this to be a reverdable migration.
class Profile < ActiveRecord::Base
file_column :icon, :magick => {
:versions => {
:big => {:crop => "1:1", :size => "150x150", :name => "big"},
:medium => {:crop => "1:1", :size => "100x100", :name => "medium"},
:small => {:crop => "1:1", :size => "50x50", :name => "small"}
}
}
alias_method :old_icon=, :icon=
alias_method :old_icon, :icon

has_attached_file :icon, :styles => { :big => "150x150>", :medium => "100x100>", :small => "50x50>" }
end

class Photo < ActiveRecord::Base
file_column :image, :magick => {
:versions => {
:square => {:crop => "1:1", :size => "50x50", :name => "square"},
:small => "175x250>"
}
}
alias_method :old_image=, :image=
alias_method :old_image, :image

has_attached_file :image, :styles => { :square => "50x50#", :small => "175x250>"}
end
6 changes: 3 additions & 3 deletions test/fixtures/photos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
first:
caption: this is just a test photo.
profile: user
image: photo_1.jpg
image_file_name: photo_1.jpg



second:
caption: this is just a test photo.
profile: user
image: photo_2.jpg
image_file_name: photo_2.jpg



third:
caption: this is just a test photo.
profile: user
image: photo_3.jpg
image_file_name: photo_3.jpg
2 changes: 1 addition & 1 deletion test/fixtures/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ user:
last_name: Veloper
email: user@example.com
is_active: true
icon: user.png
icon_file_name: user.png

user2:
user: user2
Expand Down
8 changes: 4 additions & 4 deletions test/functional/profiles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ class ProfilesControllerTest < ActionController::TestCase
#raise (p.send :icon_state).inspect
assert_not_nil p.icon
get :show, {:id => p.id, :public_view => true}, {:user => p.id}
assert_tag :img, :attributes => { :src => /\/system\/profile\/icon\/\d*\/big\/user.png/ }
assert_tag :img, :attributes => { :src => /\/system\/icons\/\d*\/big\/user.png/ }
end

should 'use gravatar otherwise' do
p = profiles(:user2)
assert_nil p.icon
assert !p.icon.file?
get :show, {:id => p.id}, {:user => p.id, :public_view => true}
assert_tag :img, :attributes => {:src => /www\.gravatar\.com/}
end

should 'send the app\'s internal default as the default to gravatar' do
p = profiles(:user2)
assert_nil p.icon
assert !p.icon.file?
get :show, {:id => p.id}, {:user => p.id, :public_view => true}
assert_tag :img, :attributes => { :src => /http...www.gravatar.com\/avatar\/[0-9a-f]+\?size\=50&amp;default\=http...test\.host\/images\/avatar_default_small\.png/ }
end
Expand All @@ -148,7 +148,7 @@ class ProfilesControllerTest < ActionController::TestCase
assert_not_nil profiles(:user).icon
post :delete_icon, {:id => profiles(:user).id, :format => 'js'}, {:user => profiles(:user).id}
assert_response :success
assert_nil assigns(:p).reload.icon
assert !assigns(:p).reload.icon.file?
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# for testing uploaded files
# place any "already uploaded" files in a subdirectory within /test/ instead of overwriting production files.
FileColumn::ClassMethods::DEFAULT_OPTIONS[:root_path] = File.join(RAILS_ROOT, 'test', "public", 'system')
# FileColumn::ClassMethods::DEFAULT_OPTIONS[:root_path] = File.join(RAILS_ROOT, 'test', "public", 'system')

class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
Expand Down
2 changes: 1 addition & 1 deletion test/unit/photo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class PhotoTest < ActiveSupport::TestCase
context "A Photo instance" do

should_belong_to :profile
should_require_attributes :image, :profile_id
should_require_attributes :profile_id
end
end
69 changes: 0 additions & 69 deletions vendor/plugins/file_column/CHANGELOG

This file was deleted.

Loading

0 comments on commit 7734427

Please sign in to comment.