Coding a "Log user File downloads" plugin - "is not missing constant" error
Added by Matt Henderson over 12 years ago
Hello everyone,
I've started writing a Plugin to record a log of User downloads from the Files section. I have monkey-patched the download
function in AttachmentsController
using alias_method_chain
which calls the original and then creates a new entry in a new database table download_logs
. I am having a bit of a problem with an error.
The data saving works fine, but when I display the log entries with the controller index
, I get a 500 error - but only the first time the page loads. Hitting refresh causes the page to load fine and show my table of logs, and it then works until I sign out (and maybe quit the browser, it always crashed first time after a server restart).
The download_logs_controller
is:
class DownloadLogsController < ApplicationController unloadable before_filter :find_project, :authorize, :only => :index def index @project = Project.find(params[:project_id]) @download_logs = DownloadLog.find(:all, :conditions => {:project_id => @project.id}) end def log_download end def find_project @project = Project.find(params[:project_id]) end end
The first bit of the production.log
is below, I have only taken the top entries as it is quite long:
Processing DownloadLogsController#index (for ip.add.res.s at 2012-05-11 13:54:56) [GET] Parameters: {"project_id"=>"lossie", "action"=>"index", "controller"=>"download_logs"} ArgumentError (Object is not missing constant DownloadLog!): /usr/lib/ruby/1.8/active_support/dependencies.rb:417:in `load_missing_constant' /usr/lib/ruby/1.8/active_support/dependencies.rb:80:in `const_missing' /usr/lib/ruby/1.8/active_support/dependencies.rb:92:in `const_missing' /usr/lib/ruby/1.8/active_support/dependencies.rb:98:in `send' /usr/lib/ruby/1.8/active_support/dependencies.rb:98:in `const_missing' vendor/plugins/redmine_download_logger/app/controllers/download_logs_controller.rb:8:in `index' /usr/lib/ruby/1.8/action_controller/base.rb:1331:in `send' /usr/lib/ruby/1.8/action_controller/base.rb:1331:in `perform_action_without_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:617:in `call_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:610:in `perform_action_without_benchmark' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/action_controller/rescue.rb:160:in `perform_action_without_flash' /usr/lib/ruby/1.8/action_controller/flash.rb:146:in `perform_action'
And the environment info:
Ruby version 1.8.7 (i486-linux) RubyGems version 1.3.7 Rack version 1.1 Rails version 2.3.5 Active Record version 2.3.5 Active Resource version 2.3.5 Action Mailer version 2.3.5 Active Support version 2.3.5 Edge Rails revision unknown Application root /usr/share/redmine Environment production Database adapter mysql Database schema version 20100819172912 About your Redmine plugins SCM Creator 0.3.0 Redmine Download Logger plugin 0.0.1
I have read a fair bit on the "is not missing constant" error. From what I have picked up it's something to do with the autoloader in Rails trying to reload DownloadLog - but most of the problems I have found are caused by namespace issues, which I can't see how to apply to this code. I followed the Redmine Plugin tutorial fairly well (as far as I know), so I'm not sure what has happened with the controller/model loading.
I am happy to post more code/logging, I kept it to a minimum as I don't know enough about Redmine/Ruby on Rails to know what to post :)
Also happy to share the Plugin if people are interested, even though it's not very complicated/featured - although I'm not sure of the best way to do this.
Thank you for your time.
Best regards,
Matt
Replies (1)
RE: Coding a "Log user File downloads" plugin - "is not missing constant" error - Added by Schollii Tron over 11 years ago
I'm looking for same feature. Any progress on this?