Skip to content

msadouni/dragonfly_helper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dragonfly helper : SEO friendly URLs and cache with Dragonfly

I really love using Dragonfly for image handling/on-the-fly resizing with Ruby on Rails, but a major drawback are URLs like this :

<img src='/media/BAhbB1sHOgZmIjsyMDEyLzA3LzIzLzE2XzA5XzA4XzQ4NV9NYXJpZV9NQVlZQVNfU2VwaWFfZXRfVmVydC5KUEdbCDoGcDoKdGh1bWIiCjQ2eDMy' />

I also needed better performance and caching, so I wrote this simple snippet and then I got the best of both worlds : paper_clip like URLs, caching AND on the fly image resizing.

Key benefits

  • All advantages of Dragonfly (only one field in database, powerfull on-the-fly resizing...)
  • SEO friendly URLs (ex: /images/my_product.jpg)
  • Caching
  • Also handles custom attributes (data attributes, custom path...)

Drawbacks

  • Won't handle S3 or whatever cloud files

Installation

Install Dragonfly first, then simply drop 'dragonfly_helper.rb' into your helpers dir.

Usage

Quite like the regular Rails image_tag

= thumbnail_tag user.avatar, '100x100'

It will then generate a thumbnailed image and output an image tag like this

<img src='/images/user_avatar.jpg' width='100px' height='100px' alt="user_avatar" />

Or like this

= thumbnail_tag product.image, '200x50', :path => '/products/small/', :alt => product.name

So

<img src='/products/small/product_image_file_name.jpg' width='200px' height='50px' alt="such a nice product name" />

Or even...

= thumbnail_tag product.image, '200x50', :alt => product.name, :data => {:do =>'some_action', :trigger =>'that'}

Then

<img src='/products/small/product_image_file_name.jpg' width='200px' height='50px' alt="such a nice product name" data-do='some_action' data-trigger='that' />

About

A Dragonfly helper so you can cache images and pull them with a nice SEO friendly URL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published