On Monday, 20. March 2006 04:35, Sonja Krause-Harder wrote:
Hi,
on my local setup I encountered the following error when adding files to a package with the web client:
(from src/webclient/log/development.log)
rescue_action_in_public: caught NoMethodError: undefined method `file' for #<Package:0xb7576d20> default exception handling Rendering layoutfalsestatus500templateerror within layouts/application Rendering error (500)
The error goes away with the following patch:
skh@linux-4:/local/opensuse/buildservice/src/webclient/app/controllers> svn diff package_controller.rb Index: package_controller.rb =================================================================== --- package_controller.rb (revision 55)
Your working copy is out of date. This bug has already been fixed in SVN.
+++ package_controller.rb (working copy) @@ -107,6 +107,9 @@ end filetype = params[:filetype]
+ logger.debug "controller: starting to add file: #{filename}" + @package.add_file :file => file, :filename => filename, :filetype => filetype + if @package.file("@filename='#{filename}'") @package.remove_file filename flash_message = "File '#{filename}' replaced successfully" @@ -114,10 +117,7 @@ flash_message = "File '#{filename}' added successfully" end - logger.debug "controller: starting to add file: #{filename}" - @package.add_file :file => file, :filename => filename, :filetype => filety pe - - if @package.save_files and @package.save + if @package.save_files and @package.save flash[:note] = flash_message else flash[:note] = "Failed to add file '#{filename}'"
This would make it impossible to add a file. First it gets added and immediately after it removed again. The problem is that @package.file is not defined as a method but caught my method_missing (kind of equivalent to perls AUTOLOAD), so I can't really tell if I should return nil (for no file tag) or throw an exception (for no file method). Determining this from the XML Schema is planned, but not implemented yet. So the correct solution is to check if a file tag exists before calling the file method:
- if @package.file("@filename='#{filename}'") - if @package.has_element?(:file) and @package.file("@filename='#{filename}'")
I'm very puzzled that build.opensuse.org doesn't show the same error.
cheers,
Sonja
-- Andreas Bauer - Novell - SUSE Internal Tools