johncant / mailman-rails

Integrate Mailman with Rails
MIT License
16 stars 6 forks source link

Cannot require models... #3

Open lephyrius opened 11 years ago

lephyrius commented 11 years ago

I tried in the mailman.rb : require './app/models/user.rb'

For accessing the user models in my rails app. But it doesn't work. Am I doing something wrong or should I duplicate the functions? Or do I need some other kind of refactoring?

johncant commented 11 years ago

Please can you explain more about what you're doing?

lephyrius commented 11 years ago

I created a mailman.rb in the initializers directory:

# Some mailman setup removed.

Mailman::Rails.receive do

  default do
    begin
      Mailman.logger.debug message.to_s
      MailLog.receive message
    rescue Exception => e
    Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
    Mailman.logger.error [e, *e.backtrace].join("\n")
    end
  end

end

This works perfectly in development. But when I run this is production with my capistrano script:

cd #{current_path} && export RAILS_ENV=#{stage} && bundle exec rake mailman:start 

It gave me the error: "MailLog" not found. So the first thing I tried was to just:

require './app/models/mail_log.rb'

Require the models needed.

johncant commented 11 years ago

I actually don't know. My application uses Mailman::Rails in the same way, but I don't need to require my models explicitly. I'd be grateful if you could take a look through the (small amount of) code in this gem and see if there is anything that would conflict with your setup, and also post your Mailman version and Rails version.

Thankyou!

lephyrius commented 11 years ago

Then I know that im not crazy! Im using: Mailman 0.6.0 (No git branch) Rails 3.2.13

I don't see anything conflicting I get: "uninitialized constant MailLog" I will check the code another round but I havn't found anything right now that would conflict.

johncant commented 11 years ago

Mailman changes the scope in its various blocks, so my suggestion would be to try ::MailLog .

lephyrius commented 11 years ago

Tried it but gave me the same old error:

uninitialized constant MailLog
..deploy_path.../releases/20130422195939/config/initializers/mailman.rb:33:in `block (2 levels) in <top (required)>'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/router.rb:66:in `instance_exec'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/router.rb:66:in `route'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/message_processor.rb:19:in `process'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/receiver/pop3.rb:41:in `block in get_messages'
/root/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in `each'
/root/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in `each_mail'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/receiver/pop3.rb:41:in `block in get_messages'
/root/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in `each'
/root/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in `each_mail'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/receiver/pop3.rb:40:in `get_messages'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/application.rb:118:in `block in polling_loop'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/application.rb:115:in `loop'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/application.rb:115:in `polling_loop'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-0.6.0/lib/mailman/application.rb:75:in `run'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-rails-0.0.3/lib/mailman-rails.rb:31:in `run!'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-rails-0.0.3/lib/mailman-rails/tasks/mailman.rake:32:in `block in <top (required)>'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/root/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-rails-0.0.3/lib/mailman-rails/tasks/mailman.rake:18:in `block (4 levels) in <top (required)>'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `call'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `block in start_proc'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call_as_daemon'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/application.rb:259:in `start_proc'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/application.rb:296:in `start'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/controller.rb:70:in `run'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons.rb:197:in `block in run_proc'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/daemons-1.1.9/lib/daemons.rb:196:in `run_proc'
..deploy_path.../shared/bundle/ruby/2.0.0/gems/mailman-rails-0.0.3/lib/mailman-rails/tasks/mailman.rake:17:in `block (3 levels) in <top (required)>'
sergio101 commented 11 years ago

i am having the exact same problem.. i can't seem to use any of my models.. should models be accessible inside the set mailman.rb?

johncant commented 10 years ago

Did you resolve this? Pull requests welcome....

owaiswiz commented 8 years ago

I was getting the same error and I saw that you did require './app/models/mail_log.rb' but since my and yours mailman config is in config/initializers directory, this wouldn't work. I just changed it to require Rails.root.join('app','models','mail_log.rb') and now it works as expected.