Forum: Ruby on Rails Unable to recognize model - uninitialized constant Model

Posted by V M (Guest)
on 2013-03-15 11:14
(Received via mailing list)
I have a ruby on rails script that I run by issuing the command: sudo 
ruby
script/mailman_serverThe contents of this file are:

#!/usr/bin/env rubyrequire "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
    endend

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? PS: I've also tried starting the script multiple
other ways sometimes it sporadically working:

sudo bundle exec script/mailman_server
sudo bundle exec rails runner script/mailman_server
sudo bundle exec ruby script/mailman_ctl stop

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?
Posted by Colin Law (Guest)
on 2013-03-15 11:17
(Received via mailing list)
On 15 March 2013 03:12, V M <isakmper@gmail.com> wrote:
> Mailman.config.maildir = '/var/mail'
> I get an error saying:
> sudo bundle exec ruby script/mailman_ctl stop
>
> 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?

I don't know the direct answer to your problem, but I think the best
way to run scripts within the environment of an application is to use
rake, then it should all be handled for you.  That is what rake is
for.

Colin
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.