Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CarrierWave

  • Loading branch information...
commit 3826a28e4cdcc757029b29b5cee370c17f58eb10 1 parent cd90b68
@amesel amesel authored
View
3  .gitignore
@@ -17,4 +17,5 @@
.rvmrc
.sass-cache/
-public/assets/
+public/assets/
+public/uploads/
View
3  Gemfile
@@ -27,6 +27,9 @@ gem 'best_in_place'
gem 'devise'
gem 'oa-oauth', :require => "omniauth/oauth"
+gem 'carrierwave'
+gem "rmagick"
+
group :development do
gem 'sqlite3'
gem 'erb2haml'
View
5 Gemfile.lock
@@ -35,6 +35,8 @@ GEM
jquery-rails
rails (~> 3.1)
builder (3.0.0)
+ carrierwave (0.5.8)
+ activesupport (~> 3.0)
chunky_png (1.2.5)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@@ -123,6 +125,7 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rmagick (2.13.1)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
sass (3.1.16)
@@ -155,6 +158,7 @@ PLATFORMS
DEPENDENCIES
best_in_place
+ carrierwave
coffee-rails (~> 3.2.1)
compass-rails
devise
@@ -163,6 +167,7 @@ DEPENDENCIES
oa-oauth
pg
rails (= 3.2.3)
+ rmagick
sass-rails (~> 3.2.3)
sqlite3
therubyracer
View
0  app/assets/images/dummy.png → app/assets/images/fallback/default.png
File renamed without changes
View
BIN  app/assets/images/fallback/thumb_default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
15 app/models/user.rb
@@ -1,5 +1,5 @@
class User < ActiveRecord::Base
- attr_accessible :id, :image, :name, :email, :password, :remember_me, :password_confirmation
+ attr_accessible :id, :image, :remove_image, :name, :email, :password, :remember_me, :password_confirmation
has_many :authentications
has_many :parties
@@ -9,8 +9,15 @@ class User < ActiveRecord::Base
has_many :activities
validates :name, :presence => true
- validates :email, :password, :presence => true, :on => :create
+ validates :password, :presence => true, :on => :create
# validates :uid, :uniqueness => {:scope => :provider}
- devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :omniauthable
-end
+ devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
+
+ mount_uploader :image, ImageUploader
+
+ protected
+ def password_required?
+ false
+ end
+end
View
52 app/uploaders/image_uploader.rb
@@ -0,0 +1,52 @@
+# encoding: utf-8
+
+class ImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ include CarrierWave::RMagick
+ # include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ def default_url
+ "/assets/fallback/" + [version_name, "default.png"].compact.join('_')
+ end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :scale => [50, 50]
+ # end
+
+ version :thumb do
+ process :resize_to_fill => [50, 50]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
View
2  app/views/activities/_activity.html.haml
@@ -1,7 +1,7 @@
= content_tag_for :li, activity, :class => "activity" do
.icon
%a{:href => ""}
- = image_tag activity.user.image ? activity.user.image : "dummy.png", alt: activity.user.name, class: "avatar size128"
+ = image_tag activity.user.image_url(:thumb), alt: activity.user.name, class: "avatar size128"
%p= nl2br activity.content
- if user_signed_in? && current_user == activity.user
%p= link_to "delete", activity_path(activity), :method => :delete, :remote => true
View
2  app/views/parties/index.html.haml
@@ -13,7 +13,7 @@
- party.members.each do |member|
%li
%a{:href => ""}
- = image_tag member.image ? member.image : "dummy.png"
+ = image_tag member.image_url(:thumb)
.actions
%ul
%li.show= link_to 'Show', party
View
4 app/views/parties/show.html.haml
@@ -30,7 +30,7 @@
- @party.members.each do |member|
= content_tag_for :li, member do
%a{:href => ""}
- = image_tag member.image ? member.image : "dummy.png"
+ = image_tag member.image_url(:thumb)
.times
.now
.remain
@@ -51,7 +51,7 @@
.header
%h1.icon
%a{:href => ""}
- = image_tag member.image ? member.image : "dummy.png"
+ = image_tag member.image_url(:thumb)
.information
%ul
%li.name
View
11 app/views/settings/_form.html.haml
@@ -1,4 +1,4 @@
-= form_for @user, :url => settings_update_path do |f|
+= form_for @user, :url => settings_update_path, :html => {:multipart => true} do |f|
- if @user.errors.any?
#error_explanation
%h2
@@ -28,5 +28,14 @@
%br/
= f.password_field :password_confirmation
+ .field
+ = f.label :image
+ %br/
+ = image_tag @user.image_url(:thumb) if @user.image?
+ %br/
+ = f.file_field :image
+ %br/
+ = f.check_box :remove_image
+
.actions
= f.submit
View
1  config/initializers/devise.rb
@@ -198,7 +198,6 @@
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
- config.omniauth :twitter, 'C1jdrQaYUqCJvOjm5DyXfA', 'GCWGOU0QzdNcpaetdIFnZd4rB3npBFv7JzO9BXrRB0'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
Please sign in to comment.
Something went wrong with that request. Please try again.