Module: EducodeSales::ApplicationHelper
- Defined in:
- app/helpers/educode_sales/application_helper.rb
Instance Method Summary collapse
- #current?(css, path) ⇒ Boolean
- #disk_filename(source_type, source_id, image_file = nil) ⇒ Object
- #relative_path ⇒ Object
- #storage_path ⇒ Object
- #url_to_avatar(source) ⇒ Object
Instance Method Details
#current?(css, path) ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'app/helpers/educode_sales/application_helper.rb', line 4 def current?(css, path) if path.is_a?(Array) ? (current_page?(path.first) || request.path == path.last) : current_page?(path) css else ' ' end end |
#disk_filename(source_type, source_id, image_file = nil) ⇒ Object
32 33 34 |
# File 'app/helpers/educode_sales/application_helper.rb', line 32 def disk_filename(source_type,source_id,image_file=nil) File.join(storage_path, "#{source_type}", "#{source_id}") end |
#relative_path ⇒ Object
40 41 42 |
# File 'app/helpers/educode_sales/application_helper.rb', line 40 def relative_path "avatars" end |
#storage_path ⇒ Object
36 37 38 |
# File 'app/helpers/educode_sales/application_helper.rb', line 36 def storage_path File.join(Rails.root, "public", "images", relative_path) end |
#url_to_avatar(source) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/educode_sales/application_helper.rb', line 12 def url_to_avatar(source) return "" if source.blank? if File.exist?(disk_filename(source&.class, source&.id)) && File.file?(disk_filename(source&.class, source&.id)) ctime = File.ctime(disk_filename(source&.class, source&.id)).to_i if source.class.to_s == 'User' File.join(relative_path, ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}" else File.join("images/avatars", ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}" end elsif source.class.to_s == 'User' str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g" File.join(relative_path, "#{source.class}", str) elsif source.class.to_s == 'Subject' File.join("images","educoder", "index", "subject", "subject#{rand(19)}.jpg") elsif source.class.to_s == 'Shixun' File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg") end end |