Rails app not finding models

Rails app not finding models

Posted by: jwatson
Posted on: 2005-11-27 17:33:00

Hi everyone!

I've been trying to get my rails app to work on Dreamhost. I followed the below steps and it sort of works. The one controller I have that doesn't have a corresponding model works. Whenever I try using one that requires a model, I get a rails application error. Below are the steps I took:

1. Uploaded local rails app to ~/.

2. Made sure production database settings are correct in railsapp/config/database.yml.

3. Modified all instances of dispatch.cgi in the railsapp/public/.htaccess file to dispatch.fcgi. To my knowledge, there is only one line you need to change that looks like this:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

4. Modified the shebang location (#!) of ruby in the railsapp/public/dispatch.fcgi file to #!/usr/bin/ruby from whatever it was.

5. Switched to the production environment by uncommenting line 5 in railsapp/config/environment.rb.

6. Created a symlink to my site directory:

$ cd ~/railsapp
$ ln -s public ~/yoursite.com/railsapp

I also tried creating a subdomain and putting my app in the root directory. Same deal. I know the app is accessing the database correctly and it works perfectly on my local machine using script/server. Any ideas? Did I configure something wrong somewhere? Thanks!

-Joel


Re: Rails app not finding models

Posted by: twilcoxen
Posted on: 2005-11-30 11:20:00

Since the controller without the model works, it sure sounds like you aren't able to access the database. I'd copy your database settings to both development and production in your database.yml. Also, be sure that you are using the correct host setting (not localhost).

You can try the short script here:

http://convergentarts.com/articles/2005/11/23/quick-db-connection-test

to make sure. It will spit out more info if it fails and that may help with your debugging.

-Tom

-Tom Wilcoxen
convergent arts

Re: Rails app not finding models

Posted by: jwatson
Posted on: 2005-11-30 18:05:00

This is definitely not the problem. At one point, it was displaying database info in the aforementioned controller. I also grabbed that script you pointed me to and ran it. No problem pulling database info. Then I double (and triple) checked the database settings and they're correct...

-Joel

Re: Rails app not finding models

Posted by: twilcoxen
Posted on: 2005-11-30 18:17:00

Try this real quick. From your rails_root, fire up the console:

ruby script/console

From the command you get you can create one of your domain objects, for example, Person:

bob = Person.new
bob.save

This will actually be running within your rails environment. If you have any validations on the model you'll have to satisfy them. It's pretty useful in general. See what you get.

-Tom



-Tom Wilcoxen
convergent arts

Re: Rails app not finding models

Posted by: jwatson
Posted on: 2005-11-30 22:26:00

I had tried that earlier. Here's what I get:

Loading development environment.
>> t = User.new
MissingSourceFile: no such file to load -- MD5
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:214:in `require'
from script/../config/../config/../app/models/user.rb:1
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:207:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:207:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:39:in `require_or_load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:22:in `depend_on'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:178:in `require_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:178:in `require_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/dependencies.rb:194:in `const_missing'
from (irb):1

Re: Rails app not finding models

Posted by: twilcoxen
Posted on: 2005-12-01 05:25:00

It looks like you're using some sort of login system that uses MD5 and it can't find that file. Probably there's a reference to it in your Users model. It may be 'require'd in the Users model, but it can't find the source file. There should probably be a file under your /lib directory that defines MD5. (I say probably because it could also be in /vendor somewhere, but the old-school (e.g. last summer) place was in /lib.)

Can you try a model object that is simpler? Just a table and a bare minimum model class to remove any other issues. It looks like it's found your model and probably it's connecting to the database ok.

-Tom Wilcoxen
convergent arts

Re: Rails app not finding models

Posted by: jwatson
Posted on: 2005-12-01 09:29:00

I'm just using the md5.rb library that's part of the standard library to hash the password... I don't see why I should have to include it in the rails app anywhere. I'll give your suggestion a shot though and see what happens.

Re: Rails app not finding models

Posted by: jwatson
Posted on: 2005-12-01 09:32:00

Well, well, well. That appears to have fixed the problem. I commented out all references to the MD5 library and it just started working. What the crap? That library isn't a gem and I know I didn't manually install it... Why can't rails find it then?

Re: Rails app not finding models

Posted by: jwatson
Posted on: 2005-12-01 09:43:00

I figured it out. I was requiring 'MD5'. The filename is 'md5.rb' and Dreamhost servers are case-sensitive. So, once I switched the require to 'md5' everything was peachy.

Thanks for all the help!

Tags: dispatchproduction environmentfcgidreamhostrubycgiqsalocalhtaccess fileymlproduction databasedatabase settingsdirectory cdshebangsymlink