I'm really up-to-hear with frustration to the point where I don't think I'll ever try to use rails again. This is the second time I've tried to use it and I honestly can't even get started.
Anyway now that I've blown off that steam, here is a description of what's happening and where I'm stuck.
I have a site example.com. This site has a .htaccess that does a lot of redirection (it works off a single file in the document root that loads the appropriate controllers and what have you). Using cpanel, I set up blog.example.com. The document root for it is example.com/blog. I decided I might as well try to use RoR for the blog and learn something new.
I got started with this guide: http://guides.rubyonrails.org/getting_started.html -- their rails version seems to be 3.1.3. The one on my server is 3.0.9, but I don't think this should make a difference for such simple stuff. I trudged through getting things set up to use MySQL. I'm probably way off, but I at least wanted a page to print.
After installation, I created a symlink from the RoR public to the blog document root. Visiting blog.example.com displays the RoR "smoke test" page. Wonderful.
Clicking on "About your application’s environment" (links to http://blog.example.com/rails/info/properties) redirects to example.com. This is a really bad sign. I have no idea why it would redirect not just to its own document root, but to the document root of the main domain. I thought it was because of the redirection going on in example.com's .htaccess, so I removed said .htaccess. No dice -- the same redirection happens. I thought that it might be the browser cache too, but clearing the cache and even using a different browser still causes this redirection! I have to conclude that rails itself is redirecting from blog.example.com/rails/info/properties to example.com, but that doesn't make any sense -- especially since I haven't touched anything on the RoR app end at all.
Anyway, I decide to continue on. I create a controller with rails generate controller home index. The files all seem to be in order. I also updated root :to in routes.rb to home#index.
rake routes prints:
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"} root /(.:format) {:controller=>"home", :action=>"index"} I remove app/public/index.html as instructed so the default route will show up.
With the example.com/.htaccess, visiting / simply gives a 404, and visiting /first/index (or /first, /first/, or /first/index/) all redirect to example.com. Once again, I removed the .htaccess since it's probably causing the redirects. I'm not sure whether it's the server or some other black magic, but removing the .htaccess still causes redirects to example.com even though it no longer works since it needs the .htaccess to rewrite appropriately on its own. Using another browser seems to fix that, though.
However, I still get a 404 for visiting / or /first/index or any variant thereof. log/product.log has lots of:
Started GET "/first/index/" for ?.?.?.? at 2012-03-14 15:40:59 -0400 ActionController::RoutingError (No route matches "/first/index"): Started GET "/" for ?.?.?.? at 2012-03-14 15:41:57 -0400 ActionController::RoutingError (No route matches "/"): ...but rake routes shows that there are routes available for these. app/view/home/index.html.erb exists and has <h1>Home#index</h1>... What's weird is that the log does not always seem to record that error on every visit, so maybe the server or something is caching the response -- I don't know, but I do know that I get a 404 every time even though rake is even saying the routes exist (and inspecting config/routes.rb and app/controllers/home_controller.rb seems to indicate that they should exist too).
Apologies for the long summary, but this information may all be pertinent. My question is twofold:
1) How do I get blog.example.com to ignore example.com's .htaccess or otherwise ignore the redirects (assuming that it is the .htaccess causing them -- I'm not 100% sure that is the case but it seems likely). For reference, the .htaccess is:
RewriteEngine on RedirectMatch example/(.*)$ http://example.com/$1 RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1/ [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.html/$0/ [PT] 2) How do I get the RoR controllers to work period? I've followed the instructions for setting up the routes to the letter -- nothing on my end looks wrong, but I'm still getting 404s so I'm really not sure what to do.
htaccesshas nothing to do directly with rails. I recommend you to developp and debug your app locally and then to interest in deploying your app on prod...