0

I have a ruby on rails script that I run by issuing the command: sudo ruby script/mailman_server The contents of this file are:

#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
require "rb-inotify"
require "#{File.dirname __FILE__}/../config/environment"

Mailman.config.maildir = '/var/mail'

Mailman::Application.run do
    default do
        begin
            # call a model
            Bin.receive_mail(message)
        end
    end
end

I get an error saying:

E, [2013-03-15T02:06:39.555346 #6351] ERROR -- : uninitialized constant Bin
/var/www/beebin/script/mailman_server:14

Bin is a model and receive_mail() is a function in that model. Why can't my script see the model?

I feel like the rails environment isn't loading properly. What am I missing from the code or what is the best way to start the app?

user985723
  • 628
  • 2
  • 8
  • 18

1 Answers1

0

I'm not sure if it resolves your problem, but this is a prettier syntax

require File.expand_path(File.dirname(__FILE__) + '/../config/environment')

To be sure your environment is loaded, try to do Bin just after your require.

pierallard
  • 3,326
  • 3
  • 21
  • 48
  • I have put `b=Bin.all` right after the requires and it doesn't give me an error on that line. However I still get an error on line 14 which is `Bin.receive_mail(message)`. – user985723 Mar 15 '13 at 20:59