image uploading started
This commit is contained in:
parent
b7a7ae8c1b
commit
9165ac413a
8 changed files with 107 additions and 19 deletions
47
Gemfile
47
Gemfile
|
|
@ -3,31 +3,40 @@ source 'http://gemcutter.org'
|
||||||
|
|
||||||
gem 'rails', '3.0.0.beta4'
|
gem 'rails', '3.0.0.beta4'
|
||||||
gem 'bundler', '0.9.26'
|
gem 'bundler', '0.9.26'
|
||||||
gem 'mongo_mapper', :git => "http://github.com/BadMinus/mongomapper.git"
|
|
||||||
gem 'devise', :git => "http://github.com/BadMinus/devise.git"
|
gem 'thin'
|
||||||
gem 'jnunemaker-validatable', :git => "http://github.com/BadMinus/validatable.git"
|
|
||||||
|
#Security
|
||||||
|
gem 'gpgme'
|
||||||
|
gem 'devise', :git => 'http://github.com/BadMinus/devise.git'
|
||||||
|
|
||||||
|
#Mongo
|
||||||
|
gem 'mongo_mapper', :git => 'http://github.com/BadMinus/mongomapper.git'
|
||||||
|
gem 'jnunemaker-validatable', :git => 'http://github.com/BadMinus/validatable.git'
|
||||||
gem 'mongo_ext'
|
gem 'mongo_ext'
|
||||||
gem 'bson_ext'
|
gem 'bson_ext'
|
||||||
|
|
||||||
gem "haml"
|
#Views
|
||||||
gem 'roxml', :git => "git://github.com/Empact/roxml.git"
|
gem 'haml'
|
||||||
|
|
||||||
gem 'gpgme'
|
|
||||||
gem 'pubsubhubbub'
|
|
||||||
#mai crazy async stuff
|
|
||||||
#gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git', :require => 'em-synchrony/em-http'
|
|
||||||
gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http'
|
|
||||||
#gem 'rack-fiber_pool', :require => 'rack/fiber_pool'
|
|
||||||
gem 'addressable', :require => "addressable/uri"
|
|
||||||
gem 'em-websocket'
|
|
||||||
gem 'thin'
|
|
||||||
gem 'will_paginate', '3.0.pre'
|
gem 'will_paginate', '3.0.pre'
|
||||||
|
|
||||||
|
gem 'roxml', :git => 'git://github.com/Empact/roxml.git'
|
||||||
|
|
||||||
|
#Standards
|
||||||
|
gem 'pubsubhubbub'
|
||||||
|
|
||||||
|
gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http'
|
||||||
|
gem 'addressable', :require => 'addressable/uri'
|
||||||
|
gem 'em-websocket'
|
||||||
|
|
||||||
|
#File uploading
|
||||||
|
gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch
|
||||||
|
gem 'image_science'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rspec', '>= 2.0.0.beta.17'
|
gem 'rspec', '>= 2.0.0.beta.17'
|
||||||
gem 'rspec-rails', '2.0.0.beta.17'
|
gem 'rspec-rails', '2.0.0.beta.17'
|
||||||
gem "mocha"
|
gem 'mocha'
|
||||||
gem 'webrat'
|
gem 'webrat'
|
||||||
gem 'redgreen'
|
gem 'redgreen'
|
||||||
gem 'autotest'
|
gem 'autotest'
|
||||||
|
|
@ -36,10 +45,10 @@ group :test do
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem "nifty-generators"
|
gem 'nifty-generators'
|
||||||
gem "ruby-debug"
|
gem 'ruby-debug'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :deployment do
|
group :deployment do
|
||||||
gem 'sprinkle', :git => "git://github.com/rsofaer/sprinkle.git"
|
gem 'sprinkle', :git => 'git://github.com/rsofaer/sprinkle.git'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
36
app/controllers/photos_controller.rb
Normal file
36
app/controllers/photos_controller.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
class PhotosController < ApplicationController
|
||||||
|
#before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@photos = Photo.paginate :page => params[:page], :order => 'created_at DESC'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@photo = Photo.new(params[:photo])
|
||||||
|
@photo.person = current_user
|
||||||
|
|
||||||
|
if @photo.save
|
||||||
|
flash[:notice] = "Successfully uploaded photo."
|
||||||
|
redirect_to photos_url
|
||||||
|
else
|
||||||
|
render :action => 'new'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@photo = Photo.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@photo = Photo.where(:id => params[:id]).first
|
||||||
|
@photo.destroy
|
||||||
|
flash[:notice] = "Successfully deleted photo."
|
||||||
|
redirect_to root_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@photo = Photo.where(:id => params[:id]).first
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
6
app/models/photo.rb
Normal file
6
app/models/photo.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class Photo
|
||||||
|
require 'carrierwave/orm/mongomapper'
|
||||||
|
include MongoMapper::Document
|
||||||
|
|
||||||
|
mount_uploader :image, ImageUploader
|
||||||
|
end
|
||||||
17
app/uploaders/image_uploader.rb
Normal file
17
app/uploaders/image_uploader.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
class ImageUploader < CarrierWave::Uploader::Base
|
||||||
|
include CarrierWave::ImageScience
|
||||||
|
|
||||||
|
storage :grid_fs
|
||||||
|
|
||||||
|
def store_dir
|
||||||
|
"files/#{model.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def extension_white_list
|
||||||
|
%w(jpg jpeg gif png)
|
||||||
|
end
|
||||||
|
|
||||||
|
version :small_thumb do
|
||||||
|
process :resize_to_fill => [100,100]
|
||||||
|
end
|
||||||
|
end
|
||||||
6
config/initializers/carrierwave.rb
Normal file
6
config/initializers/carrierwave.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
CarrierWave.configure do |config|
|
||||||
|
config.grid_fs_database = "#diaspora-#{Rails.env}"
|
||||||
|
config.grid_fs_host = 'localhost'
|
||||||
|
config.grid_fs_access_url = "/GridFS"
|
||||||
|
config.storage = :grid_fs
|
||||||
|
end
|
||||||
|
|
@ -5,6 +5,7 @@ Diaspora::Application.routes.draw do |map|
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
resources :comments
|
resources :comments
|
||||||
resources :requests
|
resources :requests
|
||||||
|
resources :photos
|
||||||
|
|
||||||
match 'warzombie', :to => "dashboards#warzombie"
|
match 'warzombie', :to => "dashboards#warzombie"
|
||||||
match 'zombiefriends', :to => "dashboards#zombiefriends"
|
match 'zombiefriends', :to => "dashboards#zombiefriends"
|
||||||
|
|
|
||||||
BIN
spec/fixtures/bp.jpeg
vendored
Normal file
BIN
spec/fixtures/bp.jpeg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 261 KiB |
13
spec/models/photo_spec.rb
Normal file
13
spec/models/photo_spec.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
describe Photo do
|
||||||
|
it 'should upload a photo to GridFS' do
|
||||||
|
|
||||||
|
photo = Photo.new
|
||||||
|
file = File.open('/spec/fixtures/bp.jpeg')
|
||||||
|
photo.image = file
|
||||||
|
photo.save.should == true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue