Talk:Ruby on Rails

Note: Some of the older discussion has been moved to the Talk:Ruby on Rails Installation page.

Cleaned it up
Yep! Massive edit, but kept most of the recent Quickstart intact. The other quickstarts were either outdated, conflicting, or just redundant. It's a wiki so anyone can add anything back of course, but I just wanted to get the page somewhere back to being accessible and helpful for people that were setting up a Rails app at DreamHost for the first time.

[2006-06-02] Re: Rewriting the quickstart guide
Having just set up a rails application on Dreamhost, and getting a poor signal-to-noise ratio from the QuickStart Guide (Why talk about re-setting the handler to the fcgi version if it's not required? If that's a performance tweak, it doesn't belong in the Quickstart area) I offer my take on how to set it up...

rails $nameofyourrailsproject
 * 1) Go to the control panel and turn on FastCGI for your domain.
 * 2) From your shell account, go to the home directory, type:

ln -s ~/$nameofyourrailsproject/public ~/$nameofyourdomain/$nameofyourrailsproject
 * 1) (If you want to have a rails application in a subdirectory on your domain) Type:


 * 1) (If you want to have a rails application at top-level of your domain) Go to the control panel and set the folder of that domain to '$nameofyourrailsproject/public'

Anything I missed? (apart from telling the reader *what* those steps mean) More advanced advice is good, but not in a quickstart guide.

some additions: if you're transferring a locally working rails app to DH, recommended to: RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] chmod 755 public
 * create a dummy rails app using "rails myapp"
 * copy the created "dispatch.fcgi" into your public/ dir
 * edit the .htaccess to point to fcgi, like this:
 * change all the permissions:

Ditto in the signal-to-noise ratio. The quick start guide used to be usable and it's been totally murdered. -gmoore

2006-02-07 - I'd like to completely re-write the Quick Start Guide
Hey all - I think the quick start guide in the article needs an overhaul. I followed it perfectly and had trouble just piecing everything together. I've written my own DreamHost tutorial for Ruby on Rails for my visitors at www.RailsHosting.org, but in the spirit of wiki I don't want to just send people over to my site (i.e. spam the wiki), and I also have my own promo codes I'm promoting there. So - I'm asking - can I overhaul the quick start based on what I've written at my site? I truly think it will help - but take a look for yourself. Thanks. ~William ( william@railshosting.org )

It's a wiki, do it. The information here is out of date, disorganized, some of it is even harmful. Thanks for your tutorial! Meekrob 19:18, 10 Mar 2006 (PST)

Going into Production
I'm trying to figure out how to set the environment variable to production, but haven't found any information (yet). If there is information on this, a link would be swell. Apache/FastCGI: In httpd.conf, add the following option to the FastCgiServer definition. -initial-env RAILS_ENV=production


 * Dreamhost has announced that all Rails applications will begin in Production mode by default. I've added a section on switching environments, using switching to Development as the demo --Luke 06:02, 5 Aug 2005 (PDT)

Routing/Security
I can get the 'rails' command to run, but then I just see the folders when I visit the URL. Which begs these questions:
 * Shouldn't there be an .htaccess file routing requests to /public/dispatch.fcgi?
 * Is it ideal to have the all folders Web-accessible?

Response: When using a domain/subdomain make sure it points to the public folder, not just the app folder.--Nathan Colgate 10:36, 23 Jun 2005 (PDT)

Development - Production
I've been developing an app that now has live data. It looks as though this was all done in the 'development' database, by default. Now I'm trying to switch to production.

I've moved the data using mysqldump & mysql as described in wiki.dreamhost.com/index.php/Migrate_MySQL

I've edited config/databases.yml to supply the specs for the production database.

I've edited config/environment.rb to set the environment to production.

I've run script/server -e production (why do I run webrick if the server is Apache?)

NOW it's working.

Do I need to leave the "script/server job" running indefinitely? Do I need to restart it every day?

Why do I have 13 "/usr/bin/ruby1.8 dispatch.fcgi" jobs running?

Just askin'

[pirkka] I also have a Rails app running on Dreamhost and I think there is no reason to run webrick on DH. As you said the server in Apache and it uses the dispach.fcgi. The /script/server -e development is something that you can do on your dev env so that your app is always in production mode and always ready for deployment on DH... that's just my guess though.


 * Nice point :). It's changed to Apache running FastCGI. It's a solution I got from the forums, but when I start a new app I don't see || 'production', but instead development straight away. Does someone want to check this for them? --Luke 22:43, 20 Aug 2005 (PDT)

Questions and Misc. Discussion
[dshafer] The above appears not to work. It's not clear why it should. The URL "rails.example.com" is clearly not a valid URL. But I've tried www.mydomain.com/rails.rorsample.com and it gives me a 404 error. The instructions seem off somehow.

GooberDLX This demonstrates the use of creating an application on a domain/subdomain. rails.example.com is a perfectly valid domain for an URL. using www.mydomain.com/rails.rorsample.com would not be the wisest choice. When you issue the rails command, it will create the entire rails application in the directory that you specified. So for example, you have www.mydomain.com and you want the rails application to reside there...

then issue a

[server]$ rails www.mydomain.com 

follow the same directions above then add /public/ to your web directory root in the control panel.

Routing Problems
I am getting the following errors in my log/production.log:

ActionController::RoutingError (Recognition failed for "/javascripts/prototype.js") (and so on) ActionController::RoutingError (Recognition failed for "/stylesheets/scaffold.css") (and so on) ActionController::RoutingError (Recognition failed for "/images/ti_logo.png") (and so on)

These errors are probably the reasons for my surfeit of stalled .fcgi processes (see http://convergentarts.com/articles/2005/07/29) but his suggested solution (adding / before the filename) is not working for me.

I am using the rails helpers to link these files (http://wiki.rubyonrails.com/rails/show/HowToLinkToStaticFile), eg. <%= stylesheet_link_tag 'scaffold' %> generates 

<%= javascript_include_tag "prototype" %> generates 

<%= image_tag "ti_logo" %> generates 

These first two files are rails files and their location is the standard one generated by rails. Why can't it find them on Dreamhost? In my development environment (not Dreamhost, using webrick) they work just fine...

Tom Where is your web root? It should point to your public folder. If it doesn't then you'd have to adjust either your routes or your .htaccess file. It would definitely be easiest to point your web root to public.

Paul My web root is already "railsapp.domain.net/public" where "railsapp.domain.net" is a sub-domain of my domain. I've now changed it to "railsapp.domain.net/public/" as noted above in case that trailing slash matters, but no change so far. I'll give it 24 hours. I've also mapped one of the subdirectories "/images" specifically to ".../public/images" to see if that helps.

Is everyone else linking static image, css and script files within a rails sub-domain okay?

I haven't changed any other files (.htaccess, etc) because I haven't had to in other environments.

Tom I don't do anything unusual to link to static files. Here is the complete contents of my route.rb:

map.connect 'admin', :controller => 'admin/admin'  # (don't ask...) map.connect ':controller/:action/:id'

And here's linking in a JavaScript file:

<%= javascript_include_tag 'prototype' %>

And the output html:



Maybe you should try removing everything you can and test. Strip your route.rb as much as possible. Try putting together the pieces (get them out of a view source) and drop that in your browser location bar and make sure you get the file you expect. E.g. for my example, I'd have:

http://clubrs.org/javascripts/prototype.js

Abe I ran into a problem very similar to this tonight. Rails was trying to figure out what the "stylesheet" and "images" actions were, though everything else worked perfectly. Here's how I solved it: The default .htaccess file looks like this: RewriteEngine On
 * 1) For better performance replace the dispatcher with the fastcgi one
 * 2) Example:
 * 3) RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
 * 1) RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

DON'T just uncomment the RewriteRule line. Instead, go down like 10 more lines and replace: RewriteRule ^(.*)$ dispatch.cgi [QSA,L] with: RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] This gave me perfect linking with stylesheets and images.

stats
Peter Burns: The default set up of Rails on a subdomain breaks the /stats/ app for that subdomain as provided by Dreamhost. I've mucked about with my .htaccess a bit, with no luck so far, and I imagine that this is a common problem that someone out there has solved.

You've tried the suggestion right inside of the .htaccess that gets generated by Rails?

RewriteCond %{REQUEST_URI} ^/stats.* RewriteRule .* - [L]

-- GooberDLX

-- tayknight (took out a space between } and ^.) My bad, see below. - It's all gravy :)

-- GooberDLX the space should be there: RewriteCond TestString CondPattern

-- Peter Burns The rewrite portion of my .htaccess is as follows, and I get a Rails routing error when I go to http://rails.example.com/stats

RewriteEngine On RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} ^/stats.* RewriteRule .* - [L] RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

-- GooberDLX It should look like this... It basically says, if my request has a /stats .. then do .* and make it my last rule for the request.

RewriteEngine On RewriteCond %{REQUEST_URI} ^/stats.* RewriteRule .* - [L] RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

-- GooberDLX Or it might want to look like this... let us know! We want to have a solid source for doing this for any railers on DH.

RewriteEngine On RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR] RewriteCond %{REQUEST_URI} ^/failed_auth.html$ RewriteRule .* - [L] RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

-- Peter Burns Great! I can see the stats for my site for the first time. The last one -- and only the last one -- worked for me. I'm putting this on the main page, as it relates to something that everyone who uses RoR on Dreamhost deals with.

App times out
Hey guys, I run into a problem that maybe you can help me out with. Sometimes when I killall -9 dispatch.fcgi (it chooses when to do so randomly), my ruby on rails app will not start for another 15 minutes. Instead the user's browser will time out. Any ideas on this? -Richkzad

Same problem here :( -Zpinter

So now my website's in production and this has happened three times in four days >:( I double-checked the time it takes to restart and it's actually 10 minutes. What has a timeout of 10 minutes in FastCGI? -Richkzad

Check out the Suggestions page on the wiki (not the panel). I added a request for a better solution than the current state of FastCGI. -Zpinter

Great. I sent a ticket to support about 22 hours ago about this too. So in another 2 days I might hear back from them. -Richkzad

I'd be curious to find out exactly what's going on. I had the same problem after I ran a couple of switchtower deploys in rapid succession. Is there a hard limit on the number of fastcgi processes that a user can start within x amount of time? -Wam

File_column Plugin Broken
I have developed an app that uses the file_column plugin to upload images and automatically create thumbnails with the use of RMagick extensions. RMagick is an interface for the ImageMagick libraries. After some correspondence with Dreamhost support I have found out that ImageMagick is not available at this time becasue of security issues. Is this affecting all of the servers or just mine? -PsyDefect

I'm having the same issue on chalmers. I'm still trying to figure out what the issue is exactly, but the bottom line so far is that I need to build ImageMagick and RMagick from source. -carpeliam

I am having an issue with the file_column plugin too, but I don't think it has to do with RMagick. My production.log says:

undefined method `file_column_field'

Has anyone had any luck yet? Did building RMagick work? -Notbot 13:04, 25 Sep 2006 (PDT)

Oh wow! It took me forever to solve this! The problem is in file_column, not rmagick - although it can't hurt to upgrade. Open up /vendor/plugins/file_column/lib/magick_file_column.rb, and remove the 'true' parameter to the img.crop function call on line 90. Worked like a charm after that. - bentlegen

Oh wow indeed, bentlegen, let me know if you're ever in Adelaide Australia so I can buy you a beer, that did the trick for me (after spending pretty much all of today to get a fairly simple app running correctly on DH!) :D. - JamesBrooks

This "guide" is a PITA
I'm sorry, folk, but this guide has been edited and re-edited so many times that it makes virtually no sense. Each "version" of the guide should be migrated to a separate page and then a the "current" version needs to be made usable.

I'm trying to deploy my second rails app in six months on Dreamhost and, frankly, I don't recall how I got the first one to ever deploy.

rake db:migrate failure?
This shouldn't be hard, right? A Rails app that I deployed to Dreamhost can reach its MySQL database just fine. However, when running "rake db:migrate", I am presented with this lovely error message:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

This occurs whether using my old Rails app of months ago or one that I'm deploying now.

Capistrano is not a happy camper without Rake. Sure, I could upload a database dump and import it but yuck!

-

I was having this problem in production - my application wouldn't run and I was receiving the same error in the logs. I finally found this little snippet and added to dispatch.fcgi: ENV['RAILS_ENV'] = 'production'

and everything appears to work.

--Sleight42 13:56, 9 September 2007 (PDT)

Passenger
Shouldn't we have Passenger [] be in this list??!