0

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.

10
  • i'm confused, are you trying to deploy your application or simply get one running locally to develop? I'm not sure I'd try the first before the second. Commented Mar 14, 2012 at 20:35
  • @miked I guess both at the same time? Commented Mar 14, 2012 at 20:44
  • have you tried simply serving with the built in WEBrick server? Commented Mar 14, 2012 at 20:47
  • @miked I don't know what those words mean :/ Commented Mar 14, 2012 at 20:56
  • 1
    what is your front server (apache / nginx), what is your app server (webrick, thin, unicorn, passenger), and what is your setting to link them ? That seems to be a deployment issue. htaccess has 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... Commented Mar 14, 2012 at 20:57

1 Answer 1

1

Assuming you've got rails installed (which it sounds like you have). What happens with this?:

$>rails new myapplication $>cd myapplication $>rails s 

then nav to: http://localhost:3000

Sign up to request clarification or add additional context in comments.

5 Comments

I'm doing this on shared hosting rather than my own computer, so localhost is not going to work .. what is rails s?
well, there's part of your problem. Rails is painfully simple to get up and running locally (on your own computer). I'd recommend doing that before trying to configure it on a shared host. It doesn't sound like you made it to step 4 on guides.rubyonrails.org/getting_started.html as 'rails s' starts a local web server so you can see your app and develop against it.
but then how come I can see the "smoke test" landing page?
likely because it's a static page that your web server is serving up from the public directory (or whatever you have symlinked it to). For an initial try at Rails, you could not really have a worse scenario - that is trying to run on a shared host in a subdomain. Please do yourself a favor and FIRST try it out locally to understand the Rails framework, then attempt on a deployment to a shared host. There are too many variables at work here to effectively help you.
Well, I was able to get the root controller page to show up after all (I don't really know why..I didn't do anything), but the same URL to that page makes the redirect.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.