Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit 9bbb0fc

Browse files
committed
fix it so gem version works in both rails 3 and 3.1
1 parent a8a98b8 commit 9bbb0fc

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

lib/app/middleware/plupload_params_renamer.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ def initialize(app)
77

88
def call(env)
99
req = Rack::Request.new(env)
10-
if req.POST["_plupload_upload"]
11-
object, method = req.params["_plupload_upload"].split(/[\[\]]/)
12-
submethod = req.params["_plupload_upload"].split(/[\[\]]/)[-1]
13-
req.params[object] ||= {}
14-
if req.POST["_plupload_files"]
15-
req.params[object][method] = []
16-
req.POST["_plupload_files"].each_with_index do |file, i|
10+
form_hash = Rails.version < "3.1" ? req.POST : env['rack.request.form_hash']
11+
form_hash ||= {}
12+
13+
if form_hash["_plupload_upload"]
14+
object, method = form_hash["_plupload_upload"].split(/[\[\]]/)
15+
submethod = form_hash["_plupload_upload"].split(/[\[\]]/)[-1]
16+
form_hash[object] ||= {}
17+
if form_hash["_plupload_files"]
18+
form_hash[object][method] = []
19+
form_hash["_plupload_files"].each_with_index do |file, i|
1720
plupload_temp_path = "tmp/plupload-rails3/#{File.basename(file)}"
1821
FileUtils.mv(plupload_temp_path, file)
1922

20-
original_filename = req.POST["_plupload_original_names"][i]
21-
content_type = req.POST["_plupload_content_types"][i]
23+
original_filename = form_hash["_plupload_original_names"][i]
24+
content_type = form_hash["_plupload_content_types"][i]
2225

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

25-
req.params[object][method] << {submethod=>uploaded_file}
28+
form_hash[object][method] << {submethod=>uploaded_file}
2629
end
2730
else
28-
req.params[object][method] = req.params["file"]
31+
form_hash[object][method] = form_hash["file"]
2932
end
3033
end
3134

lib/plupload-rails3/asset_mover.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def plupload_asset_destination
2020
def install_plupload_assets
2121
plupload_asset_destination.keys.each do |asset_type|
2222
directory = File.join(Rails.root, plupload_asset_destination[asset_type])
23-
puts "Making directory: #{directory}"
23+
puts "Making directory: #{directory}/plupload-rails3"
2424
FileUtils.mkdir_p(directory)
2525
end
2626

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

3131
dest = File.join(Rails.root, plupload_asset_destination[:js])

lib/plupload-rails3/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module PluploadRails3
22
class Railtie < Rails::Railtie
33
initializer "plupload-rails3.configure_middleware" do |app|
4-
app.middleware.insert_before(ActionDispatch::ParamsParser, ActionDispatch::PluploadParamsRenamer)
4+
app.middleware.use ActionDispatch::PluploadParamsRenamer
55
end
66

77
rake_tasks do

0 commit comments

Comments
 (0)