PDA

View Full Version : FileUploadField - Does not pass "file" parameter (Ext JS + Ruby on Rails)



keetch
8 Feb 2010, 11:20 PM
Hi everyone. I would like to ask help here about file upload (Ext JS + Ruby on Rails).
Parameter "file" is successfully passed to the controller as params[:file] when I use the following code:



var importForm = new Ext.FormPanel({
baseCls: "x-plain",
fileUpload: true,
border: false,
frame: false,
renderTo: '<%= @name %>upload',
items: [{
xtype: "fileuploadfield",
buttonOnly: true,
cls: 'tb-import',
name: 'file',
id: "<%= @name %>file",
buttonText: "Import",
listeners: {
'fileselected': function(fb, v){
if(importForm.getForm().isValid()){
importForm.getForm().submit({
fileUpload: true,
url: '/gridview/import/',
params: {imp:"<%= @importname %> "},
waitMsg: 'Importing..',
success: function(importForm, o){
msg('Success', o.result.msg);
},
failure: function(importForm, o){
msg('Failed', o.result.msg);
}
});
}}
}
}]
});


When importForm is submitted, the controller recognizes the parameter "file" (params[:file]) because of the line "name: 'file'," ... but when I use the code below:



var btnEmployeeImport = new Ext.Toolbar.Button({
iconCls: 'icon-import',
text: 'Import',
menu: {
xtype: 'menu',
plain: true,
items: [{
xtype: "fileuploadfield",
iconCls: 'icon-import',
buttonOnly: true,
name: 'file',
cls: 'tb-import',
id: "<%= @name %>file",
buttonText: "Employees",
listeners: {
'fileselected': function(fb, v){
if(importForm.getForm().isValid()){
importForm.getForm().submit({
fileUpload: true,
url: '/gridview/import?',
params: {imp:"<%= @importname %> "},
waitMsg: 'Importing..',
success: function(importForm, o){
msg('Success', o.result.msg);
},
failure: function(importForm, o){
msg('Failed', o.result.msg);
}
});
}}
}
}]
}
});


The parameter "file" was not passed anymore because I think the fileuploadfile is already inside the menu and "name: 'file'" is not recognized already. Controller says it's nil so I can't access its property which is "original_filename".... I really need a button with menus so that the user could choose which one to upload..


Please help... :)
Thanks a lot guys!