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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_SjaQX7-Q3EJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Mar-15 10:16 UTC
Re: Unable to recognize model - uninitialized constant Model
On 15 March 2013 03:12, V M <isakmper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 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? 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?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.