[from now] 2014/01/13 14:44:08

diff --git a/Gemfile b/Gemfile
index 90153bc..ce7f3bb 100644
--- a/Gemfile
+++ b/Gemfile
@@ -68,3 +68,4 @@ group :development, :test do
 end

 gem 'paperclip'
+gem 'friendly_id', '~> 5.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9975be1..d4ad8d3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -81,6 +81,8 @@ GEM
       railties (>= 3.0.0)
     ffi (1.9.3)
     formatador (0.2.4)
+    friendly_id (5.0.2)
+      activerecord (~> 4.0.0)
     guard (2.2.5)
       formatador (>= 0.2.4)
       listen (~> 2.1)
@@ -236,6 +238,7 @@ DEPENDENCIES
   coffee-rails (~> 4.0.0)
   database_rewinder
   factory_girl_rails (~> 4.0.0)
+  friendly_id (~> 5.0)
   guard-bundler
   guard-rails
   guard-rspec
diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb
index 048a065..8ef0719 100644
--- a/app/models/screenshot.rb
+++ b/app/models/screenshot.rb
@@ -1,5 +1,7 @@
 class Screenshot < ActiveRecord::Base
+  extend FriendlyId
   has_attached_file :image, styles: { thumb: '100x100>' }, default_url: '/images/:style/missing.png',
     path: ':rails_root/public/sys_img/:id_sha1/:style.png',
     url:  "#{ActionController::Base.relative_url_root}/sys_img/:id_sha1/:style.png"
+  friendly_id :image, use: :slugged
 end
diff --git a/db/migrate/20140111015619_add_slug_to_screenshots.rb b/db/migrate/20140111015619_add_slug_to_screenshots.rb
new file mode 100644
index 0000000..cc597aa
--- /dev/null
+++ b/db/migrate/20140111015619_add_slug_to_screenshots.rb
@@ -0,0 +1,6 @@
+class AddSlugToScreenshots < ActiveRecord::Migration
+  def change
+    add_column :screenshots, :slug, :string
+    add_index  :screenshots, :slug, unique: true
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9439133..223be14 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.

-ActiveRecord::Schema.define(version: 20140110163828) do
+ActiveRecord::Schema.define(version: 20140111015619) do

   create_table "screenshots", force: true do |t|
     t.datetime "created_at"
@@ -21,6 +21,9 @@ ActiveRecord::Schema.define(version: 20140110163828) do
     t.integer  "image_file_size"
     t.datetime "image_updated_at"
     t.string   "title"
+    t.string   "slug"
   end

+  add_index "screenshots", ["slug"], name: "index_screenshots_on_slug", unique: true
+
 end
[from now] 2014/01/21 18:19:54

diff --git a/app/controllers/screenshots_controller.rb b/app/controllers/screenshots_controller.rb
index 256f5ce..e303abe 100644
--- a/app/controllers/screenshots_controller.rb
+++ b/app/controllers/screenshots_controller.rb
@@ -2,46 +2,27 @@ class ScreenshotsController < ApplicationController
   before_action :set_screenshot, only: [:show, :destroy]
   skip_before_action :verify_authenticity_token, only: [:create]

-  # GET /screenshots
-  # GET /screenshots.json
   def index
-    logger.info('test')
     @screenshots = Screenshot.all
   end

-  # GET /screenshots/1
-  # GET /screenshots/1.json
   def show
   end

-  # POST /screenshots
-  # POST /screenshots.json
   def create
-    logger.info(params)
     @screenshot = Screenshot.new
     @screenshot.image = params[:imagedata]
     @screenshot.save
     render text: screenshot_url(@screenshot)
   end

-  # DELETE /screenshots/1
-  # DELETE /screenshots/1.json
   def destroy
     @screenshot.destroy
-    respond_to do |format|
-      format.html { redirect_to screenshots_url }
-      format.json { head :no_content }
-    end
+    redirect_to screenshots_url
   end

   private
-    # Use callbacks to share common setup or constraints between actions.
-    def set_screenshot
-      @screenshot = Screenshot.find(params[:id])
-    end
-
-    # Never trust parameters from the scary internet, only allow the white list through.
-    #def screenshot_params
-    #  params[:screenshot]
-    #end
+  def set_screenshot
+    @screenshot = Screenshot.friendly.find(params[:id])
+  end
 end
diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb
index 8ef0719..43dc60d 100644
--- a/app/models/screenshot.rb
+++ b/app/models/screenshot.rb
@@ -1,7 +1,11 @@
 class Screenshot < ActiveRecord::Base
   extend FriendlyId
   has_attached_file :image, styles: { thumb: '100x100>' }, default_url: '/images/:style/missing.png',
-    path: ':rails_root/public/sys_img/:id_sha1/:style.png',
-    url:  "#{ActionController::Base.relative_url_root}/sys_img/:id_sha1/:style.png"
-  friendly_id :image, use: :slugged
+    path: ':rails_root/public/screenshots/:style/:id_sha1.png',
+    url:  "#{ActionController::Base.relative_url_root}/screenshots/:style/:id_sha1.png"
+  friendly_id :image_sha1, use: :slugged
+
+  def image_sha1
+    File.basename(image.url[/(.*)\?.*/, 1], '.png')
+  end
 end
[from now] 2014/01/22 01:48:23

diff --git a/.gitignore b/.gitignore
index 6a502e9..2fa9a4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@
 # Ignore all logfiles and tempfiles.
 /log/*.log
 /tmp
+
+/public/screenshots/