I am trying to get a simple "hello world" up and running on my server with mod_ruby. I think I got everything done but I am getting an error. I have copied and pasted the stacktrace at the bottom of the message. Any help would be greatly appreciated. The only reference to this problem was the following URL: http://groups-beta.google.com/group/comp.lang.ruby/browse_thread/thread/53c6c8a6183810ea/d2bf3b5e8e1deafd?q=in+%60undef_method%27:+undefined+method+%60extend_object%27+for+%60Singleton%27+(NameError)&_done=%2Fgroups%3Fhl%3Den%26safe%3Doff%26c2coff%3D1%26q%3Din+%60undef_method%27:+undefined+method+%60extend_object%27+for+%60Singleton%27+(NameError)%26qt_s%3DSearch+Groups%26&_doneTitle=Back+to+Search&&d#d2bf3b5e8e1deafd but I don''t completely understand the discussion and therefore don''t really understand how to go about solving my problem. Also there was a small bug in the latest rails package. The new_controller script seemed to have an extra "end" keyword at the end of the file. I just removed it and everything worked fine. Thanks, Eric **** STACKTRACE **** [Wed Dec 08 19:27:36 2004] [error] mod_ruby: error in ruby [Wed Dec 08 19:27:36 2004] [error] mod_ruby: /usr/lib/ruby/1.8/singleton.rb:167:in `undef_method'': undefined method `extend_object'' for `Singleton'' (NameError) [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/singleton.rb:167 [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `load'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `require'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /virtual/1/web/account.realsimplehosting.com/vendor/activerecord/lib/active_record/observer.rb:1 [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `load'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `require'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /virtual/1/web/account.realsimplehosting.com/vendor/activerecord/lib/active_record.rb:31 [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `load'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: ... 6 levels... [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/auto-reload.rb:77:in `require'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /virtual/1/web/account.realsimplehosting.com/www/dispatch.rbx:4 [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/apache/ruby-run.rb:53:in `load'' [Wed Dec 08 19:27:36 2004] [error] mod_ruby: from /usr/lib/ruby/1.8/apache/ruby-run.rb:53:in `handler'' _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> [Wed Dec 08 19:27:36 2004] [error] mod_ruby: error in ruby > [Wed Dec 08 19:27:36 2004] [error] mod_ruby: > /usr/lib/ruby/1.8/singleton.rb:167:in `undef_method'': undefined method > `extend_object'' for `Singleton'' (NameError)This is because you''re loading auto-reload.rb in your Apache configuration for mod_ruby. Don''t. auto-reload is a shallow approach to reloading that causes more confusion that it adds in convenience. Rails 0.9 has a much better reloading scheme that knows how to separate application and framework. You want to use that instead. That''s not really the cause of your error, though. The problem is that singleton.rb is being required twice as Ruby uses the path specified to decide whether to require once or twice. And singleton.rb is not designed to be required twice (as neither is many parts of Rails). -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
David Heinemeier Hansson wrote:> This is because you''re loading auto-reload.rb in your Apache > configuration for mod_ruby. Don''t. auto-reload is a shallow approach to > reloading that causes more confusion that it adds in convenience. Rails > 0.9 has a much better reloading scheme that knows how to separate > application and framework. You want to use that instead.I am just trying out rails and have other ruby-based apps I am developing on the server. If I disable auto-reload then won''t I have to restart the webserver every time I make a change?> That''s not really the cause of your error, though. The problem is that > singleton.rb is being required twice as Ruby uses the path specified to > decide whether to require once or twice. And singleton.rb is not > designed to be required twice (as neither is many parts of Rails).Well my app isn''t requiring it so I assume something about Ruby or Rails is causing it to be required twice with two different paths. So basically my only possible solutions are: * Turn off autoreloading meaning I will have to restart the webserver every time I make a change (not viable). * Run rails as a fcgi app or plain cgi. Are there any other alternatives? How are other people using mod_ruby and rails? Does everyone just have autoreload turned off? Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> Well my app isn''t requiring it so I assume something about Ruby or > Rails is causing it to be required twice with two different paths. So > basically my only possible solutions are: > * Turn off autoreloading meaning I will have to restart the webserver > every time I make a change (not viable).This is an interim problem with Rails 0.8. In Rails 0.9 (which is due very shortly indeed), there''s a much more clever division and approach to what to reload, how, and when. But that of course won''t help the other applications you have that runs using mod_ruby.> * Run rails as a fcgi app or plain cgi.FastCGI is the preferred production environment for Rails. Unlike mod_ruby, applications won''t walk all over each other in the shared interpreter. Due to this walk-over fact, it''s not safe to run more than one Rails application per mod_ruby setup. In Rails 0.9, WEBrick has also received a big boost making it a viable production platform for small Rails applications.> Are there any other alternatives? How are other people using mod_ruby > and rails? Does everyone just have autoreload turned off?I''m actually still running Basecamp under mod_ruby and we''ve just turned off autoreload. But of course, we also have a machine that does nothing but run Basecamp, so it''s not really a problem. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
David Heinemeier Hansson wrote:> FastCGI is the preferred production environment for Rails. Unlike > mod_ruby, applications won''t walk all over each other in the shared > interpreter. Due to this walk-over fact, it''s not safe to run more than > one Rails application per mod_ruby setup.OK, when I get back to playing with Rails I will just run it as a fcgi. Curious though. Shouldn''t fcgi have the same problems? After all you have only one interpreter running. Of course I guess the difference is that you have each rails app (and other apps) running in a different instance of the interpreter so another program can get access to the rails program. What about updates to rails apps? If I change a rails file will I have to restart the apache to get it to restart the fcgi? Or can I somehow just kill the fcgi and then apache will relaunch it when it realizes it was killed? It is starting to sound like for development I should just be using the CGI interface. On production I can put the app in fcgi or mod_ruby but I will have to turn off auto-reload on mod_ruby and restart apache anytime I deploy the development code to production. Is this a correct assessment? Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> Of course I guess the difference is that you have each rails app (and > other apps) running in a different instance of the interpreter so > another program can get access to the rails program.Each Rails application gets its own FastCGI process and each FastCGI process has its own interpreter process running. So you''re shielded off.> What about updates to rails apps? If I change a rails file will I have > to restart the apache to get it to restart the fcgi? Or can I somehow > just kill the fcgi and then apache will relaunch it when it realizes > it was killed?This is one of the biggest improvements of Rails 0.9. Rails now knows how to differentiate between application files and standard library/framework files. So application files (controllers, models, etc) are reloaded on every request while the library/frameworks are cached. This gives you the best of both worlds. No need to restart to see changes in your application and almost the full speed of a cached environment.> It is starting to sound like for development I should just be using > the CGI interface. On production I can put the app in fcgi or mod_ruby > but I will have to turn off auto-reload on mod_ruby and restart apache > anytime I deploy the development code to production. Is this a correct > assessment?On Rails 0.8.5 and below, you do indeed want to use CGI for development. In Rails 0.9 and above you want to use WEBrick or FCGI as your development environment (the beta gems are already available and very usable -- Basecamp and loads of other apps are already running on them!). Rails 0.9 also introduces two different environments for running the application: development and production. The former has this new reloading behavior while the later caches both application and framework. Meaning that you''ll want to restart the FCGI processes (or just Apache for convenience) when you deploy changes to the controllers or models. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
> > OK, when I get back to playing with Rails I will just run it as a fcgi. > Curious though. Shouldn''t fcgi have the same problems? After all you > have only one interpreter running. Of course I guess the difference is > that you have each rails app (and other apps) running in a different > instance of the interpreter so another program can get access to the > rails program. What about updates to rails apps? If I change a rails > file will I have to restart the apache to get it to restart the fcgi? Or > can I somehow just kill the fcgi and then apache will relaunch it when > it realizes it was killed?If by sharing the interpreter you mean the same ruby executable than you are right. Other than that each fcgi application runs in one or more seperated processes ( more if fcgi decites it wants to pool the application. One busy php webserver here usually is running with 6 php interpreters during peek ). If you want to update your rails apps the best way is to killall ruby or apachectl restart. Fastcgi relaunches the process right away.> > It is starting to sound like for development I should just be using the > CGI interface. On production I can put the app in fcgi or mod_ruby but I > will have to turn off auto-reload on mod_ruby and restart apache anytime > I deploy the development code to production. Is this a correct assessment?CGI is the preferred development environment. The next version of rails will support fastcgi and webrick for development by smartly reloading just the user changeable files. P.S: I would suggest to install apache / mysql on your localhost machine for rails development. Good luck ! -- Tobi http://blog.leetsoft.com
I took the previous advice given and am now running in CGI environment. I figured I would start with the simplest and work my way up. So now I have it run the cgi script and I get the following in my error_log: [Thu Dec 09 18:02:18 2004] [error] [client 64.30.162.221] (2)No such file or directory: exec of ''/virtual/1/web/account.realsimplehosting.com/www/dispatch.cgi'' failed [Thu Dec 09 18:02:18 2004] [error] [client 64.30.162.221] /usr/lib/ruby/1.8/singleton.rb:84: warning: already initialized constant FirstInstanceCall [Thu Dec 09 18:02:18 2004] [error] [client 64.30.162.221] /usr/lib/ruby/1.8/singleton.rb:84: warning: already initialized constant FirstInstanceCall [Thu Dec 09 18:02:18 2004] [error] [client 64.30.162.221] /usr/lib/ruby/1.8/singleton.rb:84: warning: already initialized constant FirstInstanceCall [Thu Dec 09 18:02:18 2004] [error] [client 64.30.162.221] Premature end of script headers: dispatch.cgi It is obviously executing the script but is getting some warnings still in the singleton class. They are only warning thought so they shouldn''t be stopping anything. But at the end the script exits without outputting anything. My hello world Rails app consists of a file called /app/controllers/user_controller.rb. This file contains the following: require ''abstract_application'' class UserController < AbstractApplicationController def index render_text ''hello world'' end end I am then calling the URL http://account.realsimplehosting.com/user/index This produces the error message at the top of this message. So my question is what am I missing this time? The only thing odd about my setup is I have a symlink called www that points to public because I have my webserver setup to look for content in the www directory. But I don''t believe this should cause any problems. Eric Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Eric Anderson wrote:> I took the previous advice given and am now running in CGI environment. > I figured I would start with the simplest and work my way up. So now I > have it run the cgi script and I get the following in my error_log:Nevermind. I just realized since I am running under the CGI environment that my #! path must be correct. I got hello world showing now. Thanks for your help. Eric _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hello, I am just now exploring Ruby and Rails. I used to use Python a long time ago, then went and started exploring Squeak. But kept comparing back to Python. I have found it difficult to go back to Python. (lack of desire) Since Ruby is supposed to be more Smalltalk like, I am exploring. BTW, I learned about Rails on comp.lang.python. :) On Thu, 9 Dec 2004 17:01:08 +0100, David Heinemeier Hansson <david-OiTZALl8rpK0mm7Ywyx6yg@public.gmane.org> wrote: [snip]>> * Run rails as a fcgi app or plain cgi. > >FastCGI is the preferred production environment for Rails. Unlike >mod_ruby, applications won''t walk all over each other in the shared >interpreter. Due to this walk-over fact, it''s not safe to run more than >one Rails application per mod_ruby setup.I have barely touched FastCGI, but my experience a year or so ago wasn''t simple. It seems to be a common experience. Have you ever looked at SCGI? http://www.mems-exchange.org/software/scgi/ Developed by the Quixote (Python) guys due to dissatisfaction with FastCGI. Their page says: " " " The SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement. " " " Seems (naively) like it might be a better fit than FastCGI. I also believe that for them it also performed better than FastCGI. They are nice and helpful should you have any questions. Just thought I would let you know. Back to exploration. Jimmie Houchin