FogBugz #127: Use CarrierWave to upload avatar images.
This commit is contained in:
parent
8aab5fe93b
commit
15b6a8e138
6 changed files with 46 additions and 26 deletions
|
|
@ -1,4 +1,6 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
attr_accessible :avatar, :remote_avatar_url
|
||||
|
||||
has_many :emails, :dependent => :destroy
|
||||
has_many :phones, :dependent => :destroy
|
||||
|
||||
|
|
@ -8,6 +10,8 @@ class Contact < ActiveRecord::Base
|
|||
accepts_nested_attributes_for :emails, :reject_if => lambda { |a| a[:address].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :phones, :reject_if => lambda { |a| a[:nr].blank? }, :allow_destroy => true
|
||||
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
|
||||
def birth_date_string
|
||||
s = birth_day.to_s || ""
|
||||
s += "." unless birth_day.nil?
|
||||
|
|
@ -17,25 +21,27 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def address_string
|
||||
if address.nil?
|
||||
return ""
|
||||
end
|
||||
return "" if address.nil?
|
||||
|
||||
s = address.street || ""
|
||||
s += " "
|
||||
s += address.housenr || ""
|
||||
s += "·" unless (address.zipcode.nil? and address.place.nil?)
|
||||
s += address.zipcode
|
||||
s += " "
|
||||
s += address.place
|
||||
unless (address.zipcode.blank? and address.place.blank?)
|
||||
s += "·"
|
||||
s += address.zipcode
|
||||
s += " "
|
||||
s += address.place
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
# very temporary
|
||||
def twitter_username
|
||||
"dummy"
|
||||
nil
|
||||
end
|
||||
|
||||
def twitter_username_link
|
||||
return nil if twitter_username.nil?
|
||||
'<a href="http://twitter.com/' + twitter_username + '">@' + twitter_username + "</a>"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
class AvatarUploader < CarrierWave::Uploader::Base
|
||||
|
||||
# Include RMagick or MiniMagick support:
|
||||
# include CarrierWave::RMagick
|
||||
include CarrierWave::RMagick
|
||||
# include CarrierWave::MiniMagick
|
||||
|
||||
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
||||
|
|
@ -36,9 +36,9 @@ class AvatarUploader < CarrierWave::Uploader::Base
|
|||
# end
|
||||
|
||||
# Create different versions of your uploaded files:
|
||||
# version :thumb do
|
||||
# process :scale => [50, 50]
|
||||
# end
|
||||
version :thumb do
|
||||
process :resize_to_limit => [99, 95]
|
||||
end
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_for @contact, :html => {:class => "form-horizontal"} do |f| %>
|
||||
<%= form_for @contact, :html => {:multipart => true, :class => "form-horizontal"} do |f| %>
|
||||
|
||||
<fieldset>
|
||||
<%# <legend>Contact details</legend> %>
|
||||
|
|
@ -6,8 +6,13 @@
|
|||
<div class="controls">
|
||||
<%= image_tag("dummy_buddy_m.png") %>
|
||||
</div>
|
||||
<%= label_tag(:avatar, "Upload file", :class => "control-label") %>
|
||||
<div class="controls">
|
||||
<span class="not_yet_implemented">(Bild kann noch nicht geändert werden.)</span>
|
||||
<%= f.file_field :avatar %><br />
|
||||
</div>
|
||||
<%= label_tag(:remote_avatar_url, "or avatar URL", :class => "control-label") %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :remote_avatar_url %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<li class="span3">
|
||||
<div class="thumbnail">
|
||||
<%= link_to (image_tag("dummy_buddy_m.png")), c %>
|
||||
<%= image_tag c.avatar_url(:thumb).to_s %>
|
||||
<h5>
|
||||
<%= link_to (c.firstname.blank? ? " ".html_safe : c.firstname), c %>
|
||||
<%= link_to (c.lastname.blank? ? " ".html_safe : c.lastname), c %>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</div>
|
||||
|
||||
<div class="span3 show_picture">
|
||||
<img src="/images/dummy_buddy_l.png" />
|
||||
<%= image_tag("dummy_buddy_m.png") %>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<span id="show_name"><%= @contact.firstname %> <%= @contact.lastname %></span>
|
||||
|
|
@ -23,16 +23,19 @@
|
|||
<em><%= email.desc %></em> <%= email.address %>
|
||||
<br />
|
||||
<% end %>
|
||||
Twitter:
|
||||
<%= @contact.twitter_username_link.html_safe %>
|
||||
<br />
|
||||
<em>shared friends</em>
|
||||
<br />
|
||||
...
|
||||
<br />
|
||||
<em>shared followers</em>
|
||||
<br />
|
||||
...
|
||||
</div>
|
||||
|
||||
<% if not @contact.twitter_username_link.nil? %>
|
||||
Twitter:
|
||||
<%= @contact.twitter_username_link.html_safe %>
|
||||
<br />
|
||||
<em>shared friends</em>
|
||||
<br />
|
||||
...
|
||||
<br />
|
||||
<em>shared followers</em>
|
||||
<br />
|
||||
...
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="span3"> </div>
|
||||
</div>
|
||||
|
|
|
|||
5
db/migrate/20120701211804_add_avatar_to_contacts.rb
Normal file
5
db/migrate/20120701211804_add_avatar_to_contacts.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddAvatarToContacts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :contacts, :avatar, :string
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue