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

Commit c2517d5

Browse files
author
Sammy Larbi
committed
fixed the problem of nested attributes for has_many relationships
1 parent 27c8137 commit c2517d5

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/app/helpers/plupload_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ def plupload(model_object, model_object_method, options={})
44
options[:max_file_size] ||= 10
55
options[:filters] ||= []
66
options[:params] ||= {}
7+
options[:field_name] ||= [model_object].flatten.pop.class.name.underscore.downcase + "[#{model_object_method}]"
78
render :partial=>'plupload/uploader_scripts', :locals=>{
89
:model_object=>model_object,
910
:model_object_method=>model_object_method,

lib/app/middleware/plupload_params_renamer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def call(env)
99
req = Rack::Request.new(env)
1010
if req.POST["_plupload_upload"]
1111
object, method = req.params["_plupload_upload"].split(/[\[\]]/)
12+
submethod = req.params["_plupload_upload"].split(/[\[\]]/)[-1]
1213
req.params[object] ||= {}
1314
if req.POST["_plupload_files"]
1415
req.params[object][method] = []
@@ -21,7 +22,7 @@ def call(env)
2122

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

24-
req.params[object][method] << {:picture=>uploaded_file}
25+
req.params[object][method] << {submethod=>uploaded_file}
2526
end
2627
else
2728
req.params[object][method] = req.params["file"]

lib/app/views/plupload/_uploader_scripts.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{
4141
authenticity_token : authtoken,
4242
"_method" : "<%= [model_object].flatten.pop.new_record? ? 'post' : 'put' %>",
43-
"_plupload_upload" : "<%= [model_object].flatten.pop.class.name.underscore.downcase %>[<%= model_object_method %>]"
43+
"_plupload_upload" : "<%= options[:field_name] %>"
4444
}
4545
),
4646
<% if options[:filters].count > 0 %>

0 commit comments

Comments
 (0)