user_gravatar_tag(user, options)
elsif user.avatar.attached?
image_tag user.avatar.variant(:resize => "100x100>"), options
- elsif user.image.file?
- image_tag user.image.url(:large), options
else
image_tag "avatar_large.png", options
end
user_gravatar_tag(user, options)
elsif user.avatar.attached?
image_tag user.avatar.variant(:resize => "50x50>"), options
- elsif user.image.file?
- image_tag user.image.url(:small), options
else
image_tag "avatar_small.png", options
end
user_gravatar_tag(user, options)
elsif user.avatar.attached?
image_tag user.avatar.variant(:resize => "50x50>"), options
- elsif user.image.file?
- image_tag user.image.url(:small), options
else
image_tag "avatar_small.png", options
end
user_gravatar_url(user, options)
elsif user.avatar.attached?
polymorphic_url(user.avatar.variant(:resize => "100x100>"))
- elsif user.image.file?
- image_url(user.image.url(:large))
else
image_url("avatar_large.png")
end
if avatar&.attached?
return avatar.variant(:resize => "50x50>").blob.download
else
- return File.read(user_avatar_file_path(user))
- end
- end
-
- def user_avatar_file_path(user)
- image = user&.image
- if image&.file?
- return image.path(:small)
- else
- return Rails.root.join("app", "assets", "images", "avatar_small.png")
+ return File.read(Rails.root.join("app", "assets", "images", "avatar_small.png"))
end
end
class User < ActiveRecord::Base
require "xml/libxml"
+ self.ignored_columns = %w[image_file_name image_fingerprint image_content_type]
+
has_many :traces, -> { where(:visible => true) }
has_many :diary_entries, -> { order(:created_at => :desc) }
has_many :diary_comments, -> { order(:created_at => :desc) }
has_one_attached :avatar
- has_attached_file :image,
- :default_url => "/assets/:class/:attachment/:style.png",
- :styles => { :large => "100x100>", :small => "50x50>" }
-
validates :display_name, :presence => true, :length => 3..255,
:exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
validates :display_name, :if => proc { |u| u.display_name_changed? },
validates :home_lon, :allow_nil => true, :numericality => true, :inclusion => { :in => -180..180 }
validates :home_zoom, :allow_nil => true, :numericality => { :only_integer => true }
validates :preferred_editor, :inclusion => Editors::ALL_EDITORS, :allow_nil => true
- validates :image, :attachment_content_type => { :content_type => %r{\Aimage/.*\Z} }
validates :auth_uid, :unless => proc { |u| u.auth_provider.nil? },
:uniqueness => { :scope => :auth_provider }
self.description = ""
self.home_lat = nil
self.home_lon = nil
- self.image = nil
self.email_valid = false
self.new_email = nil
self.auth_provider = nil
else
xml.tag! "contributor-terms", :agreed => user.terms_agreed.present?
end
- xml.tag! "img", :href => user_image_url(user) if user.avatar.attached? || user.image.file? || user.image_use_gravatar
+ xml.tag! "img", :href => user_image_url(user) if user.avatar.attached? || user.image_use_gravatar
xml.tag! "roles" do
user.roles.each do |role|
xml.tag! role.role
<label class="standard-label"><%= t ".image" %></label>
<%= user_image current_user %>
<ul class='form-list accountImage-options'>
- <% if current_user.avatar.attached? || current_user.image.file? %>
+ <% if current_user.avatar.attached? %>
<li>
<%= radio_button_tag "avatar_action", "keep", !current_user.image_use_gravatar %>
<label class='standard-label' for='avatar_action_keep'><%= t ".keep image" %></label>
</li>
<% end %>
- <% if current_user.avatar.attached? || current_user.image.file? || current_user.image_use_gravatar? %>
+ <% if current_user.avatar.attached? || current_user.image_use_gravatar? %>
<li>
<%= radio_button_tag "avatar_action", "delete" %>
<label class='standard-label' for='avatar_action_delete'><%= t ".delete image" %></label>
</li>
<% end %>
- <% if current_user.avatar.attached? || current_user.image.file? %>
+ <% if current_user.avatar.attached? %>
<li>
<%= radio_button_tag "avatar_action", "new" %>
<label class='standard-label' for='avatar_action_new'>
assert_equal "", user.description
assert_nil user.home_lat
assert_nil user.home_lon
- assert_equal false, user.image.file?
+ assert_equal false, user.avatar.attached?
assert_equal false, user.email_valid
assert_nil user.new_email
assert_nil user.auth_provider
end
def test_user_image_url
- user = create(:user, :image_file_name => "test.jpg", :image_fingerprint => "d41d8cd98f00b204e9800998ecf8427e")
+ user = create(:user)
+ user.avatar.attach(:io => File.open("test/gpx/fixtures/a.gif"), :filename => "a.gif")
gravatar_user = create(:user, :image_use_gravatar => true)
url = user_image_url(user)
- assert_match %r{^/attachments/users/images/\d{3}/\d{3}/\d{3}/large/d41d8cd98f00b204e9800998ecf8427e.jpg$}, url
+ assert_match %r{^http://test.host/rails/active_storage/representations/[^/]+/[^/]+/a.gif$}, url
url = user_image_url(gravatar_user)
assert_match %r{^http://www.gravatar.com/avatar/}, url
assert user.description.blank?
assert_nil user.home_lat
assert_nil user.home_lon
- assert_equal false, user.image.file?
+ assert_equal false, user.avatar.attached?
assert_equal "deleted", user.status
assert_equal false, user.visible?
assert_equal false, user.active?