Ruby on Rails application - No such file to load - ruby-on-rails

I'm trying to bring up an old Ruby on Rails application from a crashed server, and when I try to access it via the browser, I get this screen:
For copy-and-paste / searchability, here's the text:
Ruby on Rails application could not be loaded
---------------------------------------------
A source file that the application requires, is missing.
It is possible that you didn't upload your application files correctly. Please check whether all your application files are uploaded.
A required library may not installed. Please install all libraries that this application requires.
Further information about the error may have been written to the application's log file. Please check it in order to analyse the problem.
Error message:
no such file to load -- active_record/locking/optimistic
Exception class:
LoadError
Application root:
/srv/---REDACTED---/current
Backtrace:
---the backtrace---
That first line mentioned in the backtrace is:
include Locking::Optimistic, Locking::Pessimistic
So it's looking for active_record/locking/optimistic, which I found in a variety of other locations:
/data/srv/---REDACTED---/shared/bundle/ruby/1.8/gems/activerecord-3.0.20/lib/active_record/locking/optimistic.rb
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.20/lib/active_record/locking/optimistic.rb
/var/lib/gems/1.8/gems/activerecord-3.0.20/lib/active_record/locking/optimistic.rb
My problem is that I have no idea how to tell Ruby where to go look for the files it thinks are missing. I am not a Ruby person and I don't know how Phusion Passenger runs things, but I know most languages have concepts of "paths" to search and I'm assuming I just need to set a path somewhere.
Any ideas?

I ended up manually copying over the missing files from the
/data/srv/---REDACTED---/shared/bundle/ruby/1.8/gems/activerecord-3.0.20/lib/active_record/locking/optimistic.rb
...to the gem that was reporting the missing file, since it seemed to be the same gem and same version.
Running the bundle install didn't change anything, for some reason.

Related

Redmine 404 on some pages

I have installed Redmine on a shared Bluehost account and at first sight it seems to be working.
I followed both of these tutorials: https://my.bluehost.com/cgi/help/redmine and http://www.redmine.org/projects/redmine/wiki/RedmineInstall
But just as i started navigating around i noticed that there seem to be a routing problem because some of the pages are returning a 404 error code for a reason i don't understand yet.
The error log shows no information regarding this problem.
The url is on redmine.example.com , the user/pass are still admin/admin.
I have identified that any URL regarding a project is failing, for example:
http://redmine.example.com/projects/new
http://redmine.example.com/projects/21
http://redmine.example.com/projects/21/issues
(Currently i have reset the DB for privacy concerns)
In order to prove my theory that it was regarding the projects issue, i went into the projects controller file found in app/controllers/projects_controller.rb and tried to put some abort("Foo") here and there but i couldn't see my message with any of the links that are not working so i thought maybe the problem is not there and is probably in the routing process. So i checked the config/routes.rb file and comparing it with my local version they seem identical
I am not sure what to try next as i am not a Ruby developer. Let me know what kind of info you need in order to help debug this problem.
Eventually i got it working by using FastCGI.
In order to do that, i simply created a .htaccess file and a dispatcher.fcgi as shown in the answer here : Redmine 2 on Hostmonster apache fcgi: Rails application failed to start properly
Don't forget to SetEnv GEM_PATH to your ruby gems path in your .htaccess file and it should work after restarting (pkill dispatcher.fcgi)

Getting Xapian running in Ruby on Rails app: Couldn't detect type of database

I am trying to get a Ruby on Rails application running on Ubuntu. It utilizes Xapian in order to search for documents. I already installed the xapian-full Gem in version 1.1.3.4 as instructed by the Gemfile and I created the directory files/default where the Xapian database will probably be.
database = Xapian::Database.new('files/default');
As soon as the code runs into this line, there is an error:
IOError in SearchController#index
DatabaseOpeningError: Couldn't detect type of database
Do I need to initialize the database or something? I looked the Xapian Docs and I searched for the error message on the internet, but none of this really helped.
(Writing this answer with knowledge of Xapian, but not the xapian-full Gem, so it's possible some details may be wrong - but the error comes from Xapian, so I'm pretty sure this is on the right lines.)
The error is because you created the directory files/default. Instead, just create the files directory, and ensure the process running Xapian has permission to write to that directory.
Why does Xapian raise an error here? Well, it's because Xapian databases consist simply of a directory containing a special set of files. When Xapian::Database.new is called, it checks if the database already exists before creating a new one. In the default opening mode, if the database directory already exists, it assumes that it shouldn't overwrite whatever's there with a new database, so it tries to open the existing database. Because the directory is just empty, this throws the error you see.

Passenger "No such file to load" error for Model

I'm having a problem with deploying a Rails 3 app to a Passenger/Apache2/RVM server running Ubuntu 11.10.
I'm getting the error:
A source file that the application requires, is missing.
...
Error message: No such file to load -- Goal
Exception class: LoadError
Goal is one of my Rails Models.
I've seen a lot of people with a similar error message, but their issues seem to relate to missing bundles/gems - not model files! Their problems were resolved by ensuring permissions were set up correctly, so to that end I've got:
Apache running as www-data, as is Passenger. RVM is installed as www-data and I've chown'd the entire web app directory to www-data.
I've been wrestling with this for some time now and am really out of ideas - if anyone has any suggestions I'd be very grateful!
You might probably have the file structure of your Rails app wrong. Are you sure you have the "goal.rb" file within {your_app_root_url}/app/models/ ?
To me, if I am seeing the error when you view the app in browser, it seems like your rails app and passenger(with apache2) are working fine. The other possibility is you might be looking at wrong app folder which passenger is set up to.
It's hard to tell what's wrong. Please provide more details of how you set up your passenger with your rails app directory. Also it would help if you could show what's inside your app (app structure) and what's inside goal.rb model file.
Well I've solved it. Turned out that a work around for a problem with yaml encoded model archives (i.e. an explicit require of Goal) in a completely unrelated Model was causing the error to appear. Looks like it only rears its head in production - probably due to the differences between the class loaders used in development vs. production.
Tough one to find... the stack trace didn't include a reference to where the problem actually was!

File does not exist, while using roo in Ruby-on-rails

I am developing a small Ruby-on-rails application. I am using 'roo' gem to open an excel file.
But rails throws an IO error while attempting to open the file. It says file does not exist.
It works fine in irb. My development machine is windows. Here is my code
file ="#{RAILS_ROOT}/public/data/import.xls"
file.gsub!("\\","/")
workbook = Excel.new(file)
Any help is appreciated
thanks,
Abhilash
It would be worth using the File class here rather than creating the path and gsubbing file separators. For example:
file = File.join(RAILS_ROOT, 'public', 'data', 'import.xls')
I'm pretty sure you don't need to worry too much about using backslashes for file separators though in Windows (I've stopped developing on windows though so can't test).
You can then test whether ruby thinks the file exists by doing File.exists?(file) prior to doing anything roo-specific.
Also, are you running your rails app and console as different users? That might cause some permissions problems in one but not the other.

Rails Deployment on Win32 Best Practices: Lighty + Sgci

I've received some really great guidance from users of this site, and I'm thinking some advanced Rails people could assist me in resolving the following problem.
I'm attempting to deploy a simple Rails application on a win32 server.
I've been carefully working through these instructions (see http://functionalelegant.blogspot.com/2008/05/deploying-rails-on-windows.html) for win32 Rails application deployment.
I started from a more-or-less clean windows install, then downloaded and installed
Ruby
LightTPD
Rails
Zed's SCGI Rails Runner
Windows Server 2003 Resource Kit Tools
Ruby/DBI ADO package
After that, I've done the following:
I've commented out the line in the SCGI gem (which actually was causing trouble.)
I created the directory structure as suggested, with folders for logs.
I modified the scgi.yaml file and the Lighty config files to reflect my environmental settings.
After this, I wrote the batch scripts to start up Lighty and the SGCI process. They appear to run correctly. However, inside app-errors.log the following lines appear:
2009-05-15 16:48:06: (mod_scgi.c.2645) fcgi: got a FDEVENT_ERR. Don't know why.
2009-05-15 16:48:06: (mod_scgi.c.2469) emergency exit: scgi: connection-fd: 7 fcgi-fd: 8
Finally, when I navigate to http://localhost:xxxx/ I just see a blank page. Update: I just realized the blank page only appeared to be. Viewing the source revealed the following issue:
2C:/Ruby/lib/ruby/1.8/drb/drb.rb:573:in `load'":C:/Ruby/lib/ruby/1.8/drb/drb.rb:612:in `recv_request'":C:/Ruby/lib/ruby/1.8/drb/drb.rb:911:in `recv_request'"?C:/Ruby/lib/ruby/1.8/drb/drb.rb:1530:in `init_with_client'"<C:/Ruby/lib/ruby/1.8/drb/drb.rb:1542:in `setup_message'"6C:/Ruby/lib/ruby/1.8/drb/drb.rb:1494:in `perform'"8C:/Ruby/lib/ruby/1.8/drb/drb.rb:1589:in `main_loop'"3C:/Ruby/lib/ruby/1.8/drb/drb.rb:1585:in `loop'"8C:/Ruby/lib/ruby/1.8/drb/drb.rb:1585:in `main_loop'"4C:/Ruby/lib/ruby/1.8/drb/drb.rb:1581:in `start'"8C:/Ruby/lib/ruby/1.8/drb/drb.rb:1581:in `main_loop'"2C:/Ruby/lib/ruby/1.8/drb/drb.rb:1430:in `run'"4C:/Ruby/lib/ruby/1.8/drb/drb.rb:1427:in `start'"2C:/Ruby/lib/ruby/1.8/drb/drb.rb:1427:in `run'"9C:/Ruby/lib/ruby/1.8/drb/drb.rb:1347:in `initialize'"2C:/Ruby/lib/ruby/1.8/drb/drb.rb:1627:in `new'"<C:/Ruby/lib/ruby/1.8/drb/drb.rb:1627:in `start_service'"MC:/Ruby/lib/ruby/gems/1.8/gems/scgi_rails-0.4.3/lib/scgi.rb:402:in `run'"HC:/Ruby/lib/ruby/gems/1.8/gems/scgi_rails-0.4.3/bin/scgi_service:61"*C:/Ruby/bin/scgi_service:19:in `load'" C:/Ruby/bin/scgi_service:19: mesg" too large packet
Note that 'ruby script/server' runs just fine, but the page then can't be seen externally.
Any ideas? Please let me know if anything jumps out at you.
I wrote the chapter for this in 'Deploying Rails Applications'. http://www.pragprog.com/titles/fr_deploy/deploying-rails-applications
Basically, you want mongrel, mongrel_service, and apache 2.2 with mod_proxy_balancer for windows.
You install 2 or more instances of your app with Mongrel running on separate ports. You set the services to autostart.
Then you set up apache to balance to them.
This is all outlined in the book, and I have some older articles on my website too - if you search for "deloying rails on windows" you'll find some pretty out of date stuff. The apache+mongrel way is the best way for Windows right now, and if you need additional help, feel free to let me know. I'd be glad to help.

Resources