Module: BlogImageChecksHelper
- Defined in:
- app/helpers/blog_image_checks_helper.rb
Overview
View helper: blog image checks.
Instance Method Summary collapse
Instance Method Details
#image_lookup(image_or_id, post_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/blog_image_checks_helper.rb', line 37 def image_lookup(image_or_id, post_id) if image_or_id.is_a?(Image) image_or_id else # Direct id lookup if image_or_id.is_a?(Integer) friendly_id = image_or_id else # Extract slug from file name and desired format extension = File.extname(image_or_id) friendly_id = File.basename(image_or_id, extension) extension[0] = '' # Removes the . end begin Image.friendly.find(friendly_id) rescue StandardError => e ErrorReporting.error(e, "Image not found: #{image_or_id}. Post id #{post_id}") if Rails.env.production? # Fallback to placeholder Image.friendly.find("placeholder-b0f016") end end end |
#render_blog_images ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/blog_image_checks_helper.rb', line 4 def render_blog_images = html_escape('') posts = Post.published.order(created_at: :desc) posts.each do |post| regex = /image_tag(.*?)%}/ images = post.solution.scan(regex).flatten images.each do |image| args = image.split(",").map(&:strip) args[0] image_alt = args[1] image_url = args[5] next if image_url.blank? img = image_lookup(image_url, post.id) << content_tag(:tr) do content_tag(:td, link_to(image_tag(img.image_url(size: "150x150")), img)) + content_tag(:td) do if image_alt.present? content_tag(:span, image_alt) elsif img.title.present? fa_icon('database', family: :regular, text: img.title) end end + content_tag(:td, link_to(post.id, post)) end end end end |