Skip to content

Commit

Permalink
fix it so gem version works in both rails 3 and 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
codeodor committed Oct 11, 2011
1 parent a8a98b8 commit 9bbb0fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
25 changes: 14 additions & 11 deletions lib/app/middleware/plupload_params_renamer.rb
Expand Up @@ -7,25 +7,28 @@ def initialize(app)

def call(env)
req = Rack::Request.new(env)
if req.POST["_plupload_upload"]
object, method = req.params["_plupload_upload"].split(/[\[\]]/)
submethod = req.params["_plupload_upload"].split(/[\[\]]/)[-1]
req.params[object] ||= {}
if req.POST["_plupload_files"]
req.params[object][method] = []
req.POST["_plupload_files"].each_with_index do |file, i|
form_hash = Rails.version < "3.1" ? req.POST : env['rack.request.form_hash']
form_hash ||= {}

if form_hash["_plupload_upload"]
object, method = form_hash["_plupload_upload"].split(/[\[\]]/)
submethod = form_hash["_plupload_upload"].split(/[\[\]]/)[-1]
form_hash[object] ||= {}
if form_hash["_plupload_files"]
form_hash[object][method] = []
form_hash["_plupload_files"].each_with_index do |file, i|
plupload_temp_path = "tmp/plupload-rails3/#{File.basename(file)}"
FileUtils.mv(plupload_temp_path, file)

original_filename = req.POST["_plupload_original_names"][i]
content_type = req.POST["_plupload_content_types"][i]
original_filename = form_hash["_plupload_original_names"][i]
content_type = form_hash["_plupload_content_types"][i]

uploaded_file = ActionDispatch::Http::UploadedFile.new(:tempfile=>File.new(file), :content_type=>content_type, :filename=>original_filename)

req.params[object][method] << {submethod=>uploaded_file}
form_hash[object][method] << {submethod=>uploaded_file}
end
else
req.params[object][method] = req.params["file"]
form_hash[object][method] = form_hash["file"]
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/plupload-rails3/asset_mover.rb
Expand Up @@ -20,12 +20,12 @@ def plupload_asset_destination
def install_plupload_assets
plupload_asset_destination.keys.each do |asset_type|
directory = File.join(Rails.root, plupload_asset_destination[asset_type])
puts "Making directory: #{directory}"
puts "Making directory: #{directory}/plupload-rails3"
FileUtils.mkdir_p(directory)
end

dest = File.join(Rails.root, plupload_asset_destination[:img])
puts "Copying image assets to #{dest}"
puts "Copying image assets to #{dest}/plupload-rails3"
FileUtils.cp_r(File.join(File.dirname(__FILE__), '../public/images/plupload-rails3'), dest)

dest = File.join(Rails.root, plupload_asset_destination[:js])
Expand Down
2 changes: 1 addition & 1 deletion lib/plupload-rails3/railtie.rb
@@ -1,7 +1,7 @@
module PluploadRails3
class Railtie < Rails::Railtie
initializer "plupload-rails3.configure_middleware" do |app|
app.middleware.insert_before(ActionDispatch::ParamsParser, ActionDispatch::PluploadParamsRenamer)
app.middleware.use ActionDispatch::PluploadParamsRenamer
end

rake_tasks do
Expand Down

0 comments on commit 9bbb0fc

Please sign in to comment.