Created
September 18, 2009 18:09
-
-
Save patrick99e99/189203 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acts_as_fleximage do | |
image_directory "/media/master_images" | |
use_creation_date_based_directories true | |
# image_storage_format :jpg # the plugin is handling this now | |
require_image true | |
missing_image_message 'is required' | |
invalid_image_message 'was not a readable image' | |
# default_image_path 'public/images/image_not_available.png' | |
default_image nil | |
output_image_jpg_quality 85 | |
end | |
def downloadable?(user) | |
true # for now... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhotosController < ApplicationController | |
FLEXI_METHODS.each {|flexi| caches_page flexi } | |
FLEXI_METHODS.each do |flexi| | |
define_method flexi do | |
@photo = Photo.find(params[:id]) | |
render :template => "photos/flexi/#{flexi}" | |
end | |
end | |
SEND_FILE_METHOD = :default | |
def download | |
head(:not_found) and return if (photo = Photo.find_by_id(params[:id])).nil? | |
head(:forbidden) and return unless photo.downloadable?(current_user) | |
path = "#{RAILS_ROOT}/media/photos/#{params[:id]}/#{params[:action_name]}.#{params[:format]}" | |
head(:bad_request) and return unless File.exist?(path) && params[:format].to_s == File.extname(path).gsub(/^\.+/, '') | |
send_file_options = { :type => File.mime_type?(path) } | |
case SEND_FILE_METHOD | |
when :apache then send_file_options[:x_sendfile] = true | |
when :nginx then head(:x_accel_redirect => path.gsub(Rails.root, ''), :content_type => send_file_options[:type]) and return | |
end | |
send_file(path, send_file_options) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.resources :photos, :has_many => :comments, :collection => { :destroy_album => :delete, :zip_import => :post, :builder_index => :get }, :member => FLEXI_METHODS.each_with_object({}){|string, hash| hash[string] = :get} # this returns {:tiny_thumb_cover => :get, :builder_show => :get, etc...} | |
map.connect 'images/:id/:action_name.:format', :controller => 'photos', :action => 'download', :conditions => { :method => :get } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment