Permalink
Browse files

paperclip uploading for photos and user avatar

  • Loading branch information...
1 parent 513ebe3 commit 95284e7f437ff9b328f17caff668467ab671b6cf @bborn committed Feb 8, 2011
Showing with 781 additions and 552 deletions.
  1. +1 −1 LICENSE
  2. +0 −1 Rakefile
  3. +10 −31 app/controllers/photos_controller.rb
  4. +5 −4 app/controllers/users_controller.rb
  5. +1 −1 app/models/clipping.rb
  6. +4 −7 app/models/clipping_image.rb
  7. +3 −3 app/models/photo.rb
  8. +1 −1 app/models/user.rb
  9. +17 −26 app/views/photos/index.html.haml
  10. +10 −126 app/views/photos/new.html.haml
  11. +13 −8 app/views/photos/show.html.haml
  12. +0 −34 app/views/photos/slideshow.html.erb
  13. +1 −1 app/views/posts/_author_profile.html.haml
  14. +4 −4 app/views/users/edit.html.haml
  15. +2 −2 app/views/users/show.html.haml
  16. +625 −98 community_engine.gemspec
  17. +9 −7 config/application.yml
  18. +0 −20 config/boot.rb
  19. +1 −6 config/routes.rb
  20. +25 −0 db/migrate/077_paperclip_changes.rb
  21. +0 −51 init.rb
  22. +0 −1 install.rb
  23. +8 −55 lib/community_engine.rb
  24. 0 lib/{ → community_engine}/authenticated_system.rb
  25. 0 lib/{ → community_engine}/authenticated_test_helper.rb
  26. 0 lib/{ → community_engine}/community_engine_sha1_crypto_method.rb
  27. +17 −0 lib/community_engine/engine.rb
  28. 0 lib/{ → community_engine}/i18n_extensions.rb
  29. 0 lib/{ → community_engine}/localized_application.rb
  30. 0 lib/{ → community_engine}/rails_asset_extensions.rb
  31. 0 lib/{ → community_engine}/url_upload.rb
  32. 0 lib/{ → community_engine}/viewable.rb
  33. +0 −40 lib/engine.rb
  34. +19 −0 lib/paperclip_processors/cropper.rb
  35. +0 −20 test/functional/photos_controller_test.rb
  36. +5 −3 test/testapp/db/migrate/20110205191778_add_pages.rb
  37. +0 −1 uninstall.rb
View
@@ -9,7 +9,7 @@ plugin's website.
The MIT license:
-Copyright (c) 2008 Curbly, LLC
+Copyright (c) 2011 Curbly, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -35,7 +35,6 @@ begin
gem.add_dependency 'rack', '1.2.1'
gem.add_dependency 'configatron'
gem.add_dependency 'hpricot'
- gem.add_dependency 'rmagick'
gem.add_dependency 'htmlentities'
gem.add_dependency 'haml'
gem.add_dependency 'calendar_date_select'
@@ -1,10 +1,10 @@
-require 'pp'
+ require 'pp'
class PhotosController < BaseController
include Viewable
before_filter :login_required, :only => [:new, :edit, :update, :destroy, :create, :swfupload]
- before_filter :find_user, :only => [:new, :edit, :index, :show, :slideshow, :swfupload]
- before_filter :require_current_user, :only => [:new, :edit, :update, :destroy, :swfupload]
+ before_filter :find_user, :only => [:new, :edit, :index, :show]
+ before_filter :require_current_user, :only => [:new, :edit, :update, :destroy]
skip_before_filter :verify_authenticity_token, :only => [:create] #because the TinyMCE image uploader can't provide the auth token
@@ -23,14 +23,13 @@ def recent
def index
@user = User.find(params[:user_id])
- cond = Caboose::EZ::Condition.new
- cond.user_id == @user.id
+ @photos = Photo.where :user_id => @user.id
if params[:tag_name]
- cond.append ['tags.name = ?', params[:tag_name]]
+ @photos = @photos.where('tags.name = ?', params[:tag_name])
end
-
- @photos = Photo.recent.find(:all, :conditions => cond.to_sql, :include => :tags, :page => {:current => params[:page], :size => 30})
-
+
+ @photos = @photos.includes(:tags).recent.paginate(:page => params[:page])
+
@tags = Photo.tag_counts :conditions => { :user_id => @user.id }, :limit => 20
@rss_title = "#{configatron.community_name}: #{@user.login}'s photos"
@@ -54,10 +53,9 @@ def index
def manage_photos
if logged_in?
@user = current_user
- cond = Caboose::EZ::Condition.new
- cond.user_id == @user.id
+ @photos = Photo.where :user_id => @user.id
if params[:tag_name]
- cond.append ['tags.name = ?', params[:tag_name]]
+ @photos = @photos.where('tags.name = ?', params[:tag_name])
end
@selected = params[:photo_id]
@@ -117,8 +115,6 @@ def create
respond_to do |format|
if @photo.save
- #start the garbage collector
- GC.start
flash[:notice] = :photo_was_successfully_created.l
format.html {
@@ -152,19 +148,6 @@ def create
end
end
- def swfupload
- # swfupload action set in routes.rb
- @photo = Photo.new :uploaded_data => params[:Filedata]
- @photo.user = current_user
- @photo.album_id = params[:album_id] if params[:album_id]
- @photo.album_id = params[:album_selected] unless params[:album_selected].blank?
- @photo.save!
-
- # This returns the thumbnail url for handlers.js to use to display the thumbnail
- render :text => @photo.photo.url(:thumb)
- rescue
- render :text => "Error: #{$!}", :status => 500
- end
# PUT /photos/1
# PUT /photos/1.xml
@@ -200,10 +183,6 @@ def destroy
end
end
- def slideshow
- @xml_file = user_photos_url( {:user_id => @user, :format => :xml}.merge(:tag_name => params[:tag_name]) )
- render :action => 'slideshow'
- end
protected
@@ -1,4 +1,3 @@
-
class UsersController < BaseController
include Viewable
cache_sweeper :taggable_sweeper, :only => [:activate, :update, :destroy]
@@ -114,9 +113,9 @@ def create
def edit
@metro_areas, @states = setup_locations_for(@user)
- @skills = Skill.find(:all)
- @offering = Offering.new
- @avatar = Photo.new
+ @skills = Skill.find(:all)
+ @offering = Offering.new
+ @avatar = (@user.avatar || @user.build_avatar)
end
def update
@@ -132,6 +131,8 @@ def update
@user.tag_list = params[:tag_list] || ''
+ params[:user][:avatar_attributes].merge!(:user_id => @user.id) if params[:user] && params[:user][:avatar_attributes]
+
if @user.update_attributes(params[:user])
@user.track_activity(:updated_profile)
@@ -48,7 +48,7 @@ def owner
end
def image_uri(size = '')
- image && image.clipping_image_file.url(size) || image_url
+ image && image.asset.url(size) || image_url
end
def title_for_rss
@@ -1,10 +1,7 @@
class ClippingImage < Asset
include UrlUpload
- has_attached_file :clipping_image_file, default_s3_options.merge(
- :storage => :s3,
- :styles => { :original => '465>', :thumb => "100x100#", :medium_square => "200x200#", :medium => "200>" },
- :path => "/:attachment/:id/:basename:maybe_style.:extension")
- validates_attachment_presence :clipping_image_file
- validates_attachment_content_type :clipping_image_file, :content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
- validates_attachment_size :clipping_image_file, :less_than => 3.megabytes
+ has_attached_file :asset, configatron.clipping.paperclip_options
+ validates_attachment_presence :asset
+ validates_attachment_content_type :photo, :content_type => configatron.clipping.validation_options.content_type
+ validates_attachment_size :photo, :less_than => configatron.clipping.validation_options.max_size.to_i.megabytes
end
View
@@ -2,7 +2,7 @@ class Photo < ActiveRecord::Base
acts_as_commentable
belongs_to :album
- has_attached_file :photo, configatron.photo.paperclip_options
+ has_attached_file :photo, configatron.photo.paperclip_options.to_hash
validates_attachment_presence :photo
validates_attachment_content_type :photo, :content_type => configatron.photo.validation_options.content_type
validates_attachment_size :photo, :less_than => configatron.photo.validation_options.max_size.to_i.megabytes
@@ -17,15 +17,15 @@ class Photo < ActiveRecord::Base
validates_presence_of :user
belongs_to :user
- has_one :user_as_avatar, :class_name => "User", :foreign_key => "avatar_id"
+ has_one :user_as_avatar, :class_name => "User", :foreign_key => "avatar_id", :inverse_of => :avatar
#Named scopes
scope :recent, :order => "photos.created_at DESC"
scope :new_this_week, :order => "photos.created_at DESC", :conditions => ["photos.created_at > ?", 7.days.ago.to_s(:db)]
scope :tagged_with, lambda {|tag_name|
{:conditions => ["tags.name = ?", tag_name], :include => :tags}
}
- attr_accessible :name, :description, :photo, :crop_x, :crop_y, :crop_w, :crop_h
+ attr_accessible :name, :description, :photo, :crop_x, :crop_y, :crop_w, :crop_h, :user_id
def display_name
(self.name && self.name.length>0) ? self.name : "#{:created_at.l.downcase}: #{I18n.l(self.created_at, :format => :published_date)}"
View
@@ -68,7 +68,7 @@ class User < ActiveRecord::Base
has_many :monitorships, :dependent => :destroy
has_many :monitored_topics, :through => :monitorships, :conditions => ['monitorships.active = ?', true], :order => 'topics.replied_at desc', :source => :topic
- belongs_to :avatar, :class_name => "Photo", :foreign_key => "avatar_id"
+ belongs_to :avatar, :class_name => "Photo", :foreign_key => "avatar_id", :inverse_of => :user_as_avatar
belongs_to :metro_area
belongs_to :state
belongs_to :country
@@ -1,37 +1,28 @@
.yui-b
= render :partial => 'posts/author_profile', :locals => {:user => @user}
+
-box :id => 'tag_list', :class => 'yui-u first' do
%h3=:tags.l
%ul.tags
- - @tags.each do |tag|
- %li
- - if (tag.name.eql?(params[:tag_name]) )
- = link_to tag.name, user_photos_path(@user), :class => "selected"
- - else
- = link_to tag.name, user_photos_path(:user_id => @user, :tag_name => tag.name)
+ - @tags.each do |tag|
+ %li
+ - if (tag.name.eql?(params[:tag_name]) )
+ = link_to tag.name, user_photos_path(@user), :class => "selected"
+ - else
+ = link_to tag.name, user_photos_path(:user_id => @user, :tag_name => tag.name)
#yui-main
.yui-b
- .yui-gd
- =box :id => 'tag_list', :class => 'yui-u first' do
- %h3=:tags.l
- %ul.tags
- - @tags.each do |tag|
- %li
- - if (tag.name.eql?(params[:tag_name]) )
- = link_to tag.name, user_photos_path(@user), :class => "selected"
- - else
- = link_to tag.name, user_photos_path(:user_id => @user, :tag_name => tag.name)
-
- =box :id => "photos", :class => "yui-u" do
- %h3= link_to :users_photos.l(:user=>@user.login), user_photos_path(@user)
- = link_to( :new_photo.l, new_user_photo_path(@user), {:class => 'right'}) if @is_current_user
-
- .clear
- - @photos.each do |photo|
- = link_to image_tag( photo.photo.url(:thumb), :class => "polaroid"), user_photo_path(@user, photo)
-
- .pagination=paginating_links @photos if @photos.total_pages > 1
+
+ -box :id => "photos" do
+ %h3= link_to :users_photos.l(:user=>@user.login), user_photos_path(@user)
+ = link_to( :new_photo.l, new_user_photo_path(@user), {:class => 'right'}) if @is_current_user
+ .clear
+ - @photos.each do |photo|
+ = link_to tag('img', :src => photo.photo.url(:thumb), :class => "polaroid"), user_photo_path(@user, photo)
+ .pagination=paginating_links @photos if @photos.total_pages > 1
+
+
Oops, something went wrong. Retry.

0 comments on commit 95284e7

Please sign in to comment.