SEO optimized image URLs with the Paperclip Rails plugin

Tagged paperclip, rails, ruby, plugin, seo, url  Languages ruby

Create config/initializers/paperclip.rb:

Paperclip.interpolates :to_param do |attachment, style|

In the model:

has_attached_file :image, 
                    :path => ":rails_root/public/images:to_param/:style/:basename.:extension",
                    :url => "/images:to_param/:style/:basename.:extension",
                    :styles => { :large  => "250x360#",
                                 :medium => "150x230#",
                                 :small  => "110x150#" }

Instead of URLs like:


You can get a URL based on, for example, a permalink as in the example above. In my case I get URLs like this: