How do I get Rails3 apps running correctly in a subdirectory (ie. http://username.webfactional.com/app_name/)

Without touching the routes file, I can access login/public pages (etc).
By adding:

ENV['RAILS_RELATIVE_URL_ROOT'] = "/app_name"

the static files work.

Now I need the links/routes to work correctly. Using scoped routes:

scope "/app_name" do
#routes
end

are the "official" way to do this. However, I assume due to how Apache handles the app requests the /app_name/ part of the route never makes it to the mapping. I always get this error:

Started GET "/login" for 184.249.245.111 at Thu Jan 06 14:20:29 -0600 2011
ActionController::RoutingError (No route matches "/login"):

Obviously, /login won't exists since the scoping makes the url matching /app_name/login.
Any work arounds?

asked 06 Jan '11, 14:43

holtkampw's gravatar image

holtkampw
26117
accept rate: 0%

Did you try just mounting the application to that sub-directory in the control panel? Most frameworks will 'just-work' set up like this.

(06 Jan '11, 15:51) johns ♦♦ johns's gravatar image

I created the application and linked the application (websites tab) in the control panel. I can access static files (stylesheets, javascript, etc) from the subdirectory so the apache/nginx/passenger transfer is OK.

The rails routes are the issue, not being able to understand it is in a subdirectory. So every route says "Route not found". The url passed to it from passenger is only "/route". That's a problem since it's looking for "/route" instead of "/app_name/route"

(06 Jan '11, 16:13) holtkampw holtkampw's gravatar image

Have you tried adding,

config.action_controller.relative_url_root = "/app_name"

To your environments.rb file? This line must be added within the config block or it will not work. The first line in the config block will look like this:

Rails::Initializer.run do |config|
link

answered 06 Jan '11, 16:35

johns's gravatar image

johns ♦♦
4.1k28
accept rate: 23%

edited 06 Jan '11, 16:36

That is the Rails 2.X way of doing things. I'm looking for a Rails3 solution.

That line just gives an ArgumentError.

(06 Jan '11, 16:42) holtkampw holtkampw's gravatar image

My bad, I use Django 98% of the time and only dabble in ruby. It looks like this is still the same syntax but it resides in another file, application.rb. Some good information on this may be found here,

http://guides.rubyonrails.org/configuring.html

http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade

(06 Jan '11, 17:33) johns ♦♦ johns's gravatar image

Thanks for the attempt in helping me anyways. I do appreciate it. That Rails 2.X method is much easier than the Rails 3.X way

There is an "official" way to do this (using the scope), but it doesn't work (or I can't get it to work) on the Webfaction stack. Something is fishy in the Apache to Nginx transfer that the routes don't like.

(06 Jan '11, 17:37) holtkampw holtkampw's gravatar image

Hi,

Can you submit a ticket so I can take a closer look at the problem you are having here? I can see what is happening but without seeing the routes and config files I can't really make any suggestions.

(06 Jan '11, 18:35) klynton klynton's gravatar image

Sent! Thanks for the help.

(06 Jan '11, 18:41) holtkampw holtkampw's gravatar image

For those who have the same question:

The Official Answer from Webfaction is that its not possible on their servers.

Their front-end server removes the /app_name when it sends requests so the routes will never see that. The only option is to duplicate all routes. The first copy is your normal copy. The second copy is scoped to use your "/app_name" in front.

Either all that work, or use a subdomain (what I did).

link

answered 12 Jan '11, 10:14

holtkampw's gravatar image

holtkampw
26117
accept rate: 0%

All attempts failed. I ended up using a subdomain.

(05 Mar '12, 05:11) tamersalama tamersalama's gravatar image
link

answered 09 Sep '11, 16:42

lassebunk's gravatar image

lassebunk
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×27
×9
×2
×1

Asked: 06 Jan '11, 14:43

Seen: 4,478 times

Last updated: 05 Mar '12, 05:11

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited