Giter Site home page Giter Site logo

dragonfly_helper's Introduction

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' />

dragonfly_helper's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

msadouni duarme

dragonfly_helper's Issues

this_image is not defined

In your last version this_image is not defined (line 13), you should change it with image, would you like a pull request?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.