Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added avatar.
- Loading branch information
Giang NGUYEN
committed
Apr 18, 2012
1 parent
b3acf36
commit 36fc64c
Showing
10 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# encoding: utf-8 | ||
class AvatarUploader < CarrierWave::Uploader::Base | ||
# Include RMagick or MiniMagick support: | ||
include CarrierWave::RMagick | ||
# include CarrierWave::MiniMagick | ||
|
||
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: | ||
# include Sprockets::Helpers::RailsHelper | ||
# include Sprockets::Helpers::IsolatedHelper | ||
|
||
# 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 | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/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 :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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
<% provide(:title, "Edit user") %> | ||
<% provide(:title, "Edit user") %> | ||
<h1>Update your profile</h1> | ||
|
||
<div class="row"> | ||
<div class="span6 offset3"> | ||
<%= form_for(@user) do |f| %> | ||
<%= render 'shared/error_messages', :object => f.object %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<%= f.label :email %> | ||
<%= f.text_field :email %> | ||
<%= f.label :password %> | ||
<%= f.password_field :password %> | ||
<%= f.label :password_confirmation, "Confirm Password" %> | ||
<%= f.password_field :password_confirmation %> | ||
<%= simple_form_for @user do |f| %> | ||
Avatar: | ||
<%- if @user.avatar_url -%> | ||
<%= image_tag(@user.avatar_url(:thumb)) -%> | ||
<%- else -%> | ||
Not set. | ||
<%- end -%> | ||
<%= f.file_field :avatar -%> | ||
<%= f.hidden_field :avatar_cache -%> | ||
<%= f.input :name -%> | ||
<%= f.input :email %> | ||
<%= f.input :password %> | ||
<%= f.input :password_confirmation, :required => false %> | ||
<%= f.submit "Save changes", :class => "btn btn-large btn-primary" %> | ||
<% end %> | ||
<%= gravatar_for @user %> | ||
<a href="http://gravatar.com/emails">change</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CarrierWave.configure do |config| | ||
config.cache_dir = "#{Rails.root}/tmp/uploads" | ||
|
||
if Rails.env.production? | ||
config.fog_credentials = { | ||
:provider => 'AWS', # required | ||
:aws_access_key_id => 'AKIAJATKGAWCCDNFZN6Q', # required | ||
:aws_secret_access_key => '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', # required | ||
:region => 'us-east-1' # optional, defaults to 'us-east-1' | ||
} | ||
config.storage = :fog | ||
config.permissions = 0666 | ||
config.fog_directory = 'assets-banktracker' # required | ||
config.fog_public = true # optional, defaults to true | ||
|
||
elsif Rails.env.development? | ||
config.storage = :file | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAvatarToUser < ActiveRecord::Migration | ||
def change | ||
add_column :users, :avatar, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.