From d6ced88bcbde0228287b7164239404a255e6c614 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Mon, 11 Oct 2010 16:03:34 +0200 Subject: [PATCH] various rails3 migrations --- .gems | 4 -- Gemfile | 13 +++-- Gemfile.lock | 22 ++++++-- app/controllers/albums_controller.rb | 4 +- app/controllers/collections_controller.rb | 4 +- app/controllers/photos_controller.rb | 2 + app/uploaders/file_uploader.rb | 15 +++--- app/views/albums/show.html.erb | 4 +- app/views/layouts/application.html.erb | 4 +- app/views/layouts/application.iphone.erb | 2 +- config/balder.rb | 11 ++-- config/database.example.yml | 10 ++-- config/routes.rb | 65 +++++++++++++++++------ db/schema.rb | 13 ++--- 14 files changed, 110 insertions(+), 63 deletions(-) delete mode 100644 .gems diff --git a/.gems b/.gems deleted file mode 100644 index 566aaaa..0000000 --- a/.gems +++ /dev/null @@ -1,4 +0,0 @@ -authlogic -carrierwave -aws-s3 -mini_exiftool diff --git a/Gemfile b/Gemfile index b17b4a3..08b746b 100644 --- a/Gemfile +++ b/Gemfile @@ -6,16 +6,19 @@ gem "authlogic" gem 'mime-types', :require => 'mime/types' gem "carrierwave", :git => 'git://github.com/jnicklas/carrierwave.git' # MySQL: -gem "mysql2" +#gem "mysql2" # PostgreSQL: -#gem 'pg' +gem 'pg' + +# S3 support +gem 'fog' # ImageMagick: -#gem "rmagick", :require => 'RMagick' +gem "rmagick", :require => 'RMagick' # FreeImage: -#gem "image_science", :git => 'git://github.com/perezd/image_science.git' #gem "RubyInline" +#gem "image_science", :git => 'git://github.com/perezd/image_science.git' # MiniMagick -gem "mini_magick" \ No newline at end of file +#gem "mini_magick" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 83090a6..de50597 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,14 +42,26 @@ GEM builder (2.1.2) erubis (2.6.6) abstract (>= 1.0.0) + excon (0.2.3) + fog (0.3.7) + builder + excon (>= 0.2.3) + formatador (>= 0.0.15) + json + mime-types + net-ssh (~> 2.0.23) + nokogiri (~> 1.4.3.1) + ruby-hmac + formatador (0.0.15) i18n (0.4.1) + json (1.4.6) mail (2.2.6.1) activesupport (>= 2.3.6) mime-types treetop (>= 1.4.5) mime-types (1.16) - mini_magick (2.1) - subexec (~> 0.0.4) + net-ssh (2.0.23) + nokogiri (1.4.3.1) pg (0.9.0) polyglot (0.3.1) rack (1.2.1) @@ -71,7 +83,8 @@ GEM rake (>= 0.8.4) thor (~> 0.14.0) rake (0.8.7) - subexec (0.0.4) + rmagick (2.13.1) + ruby-hmac (0.4.0) thor (0.14.1) treetop (1.4.8) polyglot (>= 0.3.1) @@ -83,7 +96,8 @@ PLATFORMS DEPENDENCIES authlogic carrierwave! + fog mime-types - mini_magick pg rails (= 3.0.0) + rmagick diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 3058654..cd51129 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -59,8 +59,8 @@ class AlbumsController < ApplicationController unless params[:collection_id].empty? @album.collections << Collection.find( params[:collection_id] ) end - flash[:notice] = "Album created!" - redirect_to @album + flash[:notice] = "Album created! Now add some nice photos." + redirect_to upload_album_photos_path( @album ) else render :action => :new end diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index c96a8ae..bd67f8e 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -29,8 +29,8 @@ class CollectionsController < ApplicationController def create @collection = Collection.new(params[:collection]) if @collection.save - flash[:notice] = "Collection created!" - redirect_to @collection + flash[:notice] = "Collection created! Now lets add a new album." + redirect_to new_collection_album_path(@collection) else render :action => :new end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 24e4699..cb8d3d8 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -74,7 +74,9 @@ class PhotosController < ApplicationController end def create + puts "create" @photo = Photo.new(params[:photo]) + puts @photo.inspect respond_to do |format| if @photo.save format.html { render :text => "FILEID:" + @photo.file.album.url } diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index c544479..41ac66b 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -3,11 +3,10 @@ class FileUploader < CarrierWave::Uploader::Base # Include RMagick or ImageScience support - # include CarrierWave::RMagick + include CarrierWave::RMagick # include CarrierWave::ImageScience - include CarrierWave::MiniMagick + # include CarrierWave::MiniMagick # Choose what kind of storage to use for this uploader - #storage :file if ENV['S3_KEY'] storage :s3 @@ -22,7 +21,7 @@ class FileUploader < CarrierWave::Uploader::Base # This is a sensible default for uploaders that are meant to be mounted: def store_dir #{}"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" - "uploads/files/#{model.album.path}" + ENV['STORAGE_PATH'] + "/files/#{model.album.path}" end # Provide a default URL as a default if there hasn't been a file uploaded @@ -41,25 +40,25 @@ class FileUploader < CarrierWave::Uploader::Base version :collection do process :resize_to_fill => [200, 200] def store_dir - "uploads/thumbs/#{model.album.path}" + ENV['STORAGE_PATH'] + "/files/thumbs/#{model.album.path}" end end version :album do process :resize_to_fill => [100, 100] def store_dir - "uploads/thumbs/#{model.album.path}" + ENV['STORAGE_PATH'] + "/files/thumbs/#{model.album.path}" end end version :preview do process :resize_to_fit => [210, 210] def store_dir - "uploads/thumbs/#{model.album.path}" + ENV['STORAGE_PATH'] + "/files/thumbs/#{model.album.path}" end end version :single do process :resize_to_limit => [950, 950] def store_dir - "uploads/thumbs/#{model.album.path}" + ENV['STORAGE_PATH'] + "/files/thumbs/#{model.album.path}" end end diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 20f9e35..8b8a2ae 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -46,6 +46,6 @@ <%= link_to "Edit album", edit_album_path(@album) %> |  <%= link_to "Edit all photos", edit_multiple_album_photos_path(@album) %> |  <%= link_to "Edit untouched photos", untouched_album_photos_path(@album) %> |  -<%= link_to "Add photos", upload_album_photos_path(@album) %> -<% end %> +<%= link_to "Add photos", upload_collection_album_photos_path(params[:collection_id], @album) %> <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ff3862d..754a285 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,7 +3,7 @@ - <%= ENV['TITLE'] %> + <%= ENV['TITLE'] || "Photos" %> <%= yield :head %> <%= stylesheet_link_tag 'application' %> @@ -23,7 +23,7 @@ <% if ENV['LOGO'] %> <%= image_tag ENV['LOGO'] %> <% else %> - <%= ENV['TITLE'] %> + <%= ENV['TITLE'] || "Photos" %> <% end %> diff --git a/app/views/layouts/application.iphone.erb b/app/views/layouts/application.iphone.erb index b737c44..357c3c4 100644 --- a/app/views/layouts/application.iphone.erb +++ b/app/views/layouts/application.iphone.erb @@ -5,7 +5,7 @@ - <%= ENV['TITLE'] %> + <%= ENV['TITLE'] || "Photos" %> <%= yield :head %> <%= stylesheet_link_tag 'application', 'iphone' %> diff --git a/config/balder.rb b/config/balder.rb index f2d6109..2175352 100644 --- a/config/balder.rb +++ b/config/balder.rb @@ -1,6 +1,7 @@ -ENV['PUBLIC'] = 'true' -ENV['TITLE'] = 'photo' +ENV['STORAGE_PATH'] = "uploads" if ENV['STORAGE_PATH'].nil? +#ENV['PRIVATE'] = 'true' +#ENV['TITLE'] = 'photo' #ENV['HEROKU'] = 'true' -#ENV['S3_KEY'] = '' -#ENV['S3_SECRET'] = '' -#ENV['S3_BUCKET'] = '' \ No newline at end of file +#ENV['S3_KEY'] = '' +#ENV['S3_SECRET'] = '' +#ENV['S3_BUCKET'] = '' \ No newline at end of file diff --git a/config/database.example.yml b/config/database.example.yml index bf3df02..7630b54 100644 --- a/config/database.example.yml +++ b/config/database.example.yml @@ -1,19 +1,19 @@ development: adapter: postgresql - database: gallery_development - username: gallery + database: balder_development + username: balder password: changeme production: adapter: mysql encoding: utf8 - username: photogallery + username: balder password: changeme - database: gallery_production + database: balder_production socket: /var/run/mysqld/mysqld.sock test: &TEST adapter: postgresql database: gallery_test - username: gallery + username: balder password: changeme cucumber: diff --git a/config/routes.rb b/config/routes.rb index ee68f98..9339190 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,27 +1,58 @@ -ActionController::Routing::Routes.draw do |map| - map.resource :account, :controller => "users" - map.login "login", :controller => "user_sessions", :action => "new" - map.authenticate "authenticate", :controller => "user_sessions", :action => "create" - map.logout "logout", :controller => "user_sessions", :action => "destroy" +ActionController::Routing::Routes.draw do + resources :account, :as => "users" + match "login", :to => "user_sessions#new", :as => :login + match "authenticate", :to => "user_sessions#create", :as => :authenticate + match "logout", :to => "user_sessions#destroy", :as => :logout - map.resources :photos, :collection => { :untouched => :get, :edit_multiple => :post, :update_multiple => :put, :upload => :get, :scan => :get } - map.resources :albums, :collection => { :untouched => :get, } do |album| - album.resources :tags do |tag| - tag.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } + resources :photos do + collection do + get :untouched + post :edit_multiple + put :update_multiple + get :upload + get :scan end - album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } end - map.resources :collections do |collection| - collection.resources :albums do |album| - album.resources :photos, :collection => { :untouched => :get } - #album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } + resources :albums do + collection do + get :untouched + end + resources :tags do + resources :photos do + collection do + get :untouched + get :upload + get :edit_multiple + end + end + end + resources :photos do + collection do + get :untouched + get :upload + get :edit_multiple + end + end + end + resources :collections do + resources :albums do + resources :photos do + collection do + get :untouched + get :upload + get :edit_multiple + end + end end end - map.resources :tags, :has_many => [ :photos, :albums ], :shallow => true + resources :tags, :shallow => true do + resources :photos + resources :albums + end - map.resources :users, :controller => "admin/users" + resources :users, :to => "admin/users#index" - map.root :controller => "collections" + root :to => "collections#index" end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 5f587d0..aab31aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,10 +1,11 @@ -# This file is auto-generated from the current state of the database. Instead of editing this file, -# please use the migrations feature of Active Record to incrementally modify your database, and -# then regenerate this schema definition. +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your database schema. If you need -# to create the application database on another system, you should be using db:schema:load, not running -# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system.