views:

23

answers:

2

Hey. So I have a Rails app that's getting deployed to a production machine that serves it via Apache/Passenger to two subURIs.

/app
/app_2

both the above subURIs are running the same codebase. It's just two symlinks to the public dir that are both pointed to via Passenger by:

RailsBaseURI "/app"
RailsBaseURI "/app_2"

Now, imma big fan of jQuery. So I'm using it with a couple of plugins and one of them is an autocomplete function:

$("#municipality_name").autocomplete('autocomplete_municipality', {
    matchContains: true,
    scroll: false
}).result(function(event, data, formatted) {
    $.post('fill_state', {city: formatted}, null, 'script');
});

The problem I'm having is when this gets run in production, the url that gets called is

  http://www.app.com/autocomplete_municipality

rather than

http://www.app.com/app/autocomplete_municipality - or - http://www.app.com/app_2/autocomplete_municipality

(I know it's lacking the controller name in there, I have routes to give me these paths.)

Anyways, my question is, how the hell do I tell jQuery to not blow away the subURI path? config.action_controller.relative_url_root = "/signup_2" doesn't seem a viable option because I have multiple subURIs here. I am also loath to change the path in the jQuery method to be autocomplete('app/autocomplete_municipality'... since I still don't get access to my two subURIs. Maybe this is the only option.

The reason for the two URIs is mostly for internal testing --> production switchover (as we open the new site first to the company internally, then to the public at large) and we wanted to be able to launch everything at once from /app_2 (our testing path) to /app (the public path) without having to change anything on the configuration side.

Thoughts?

A: 

You could parse the current location and place that into the autocomplete's path.

var pathname = window.location.pathname;

Then concatenate the first part of the path (or however deep you need to go) into the first param of autocomplete.

(Personally, maybe a 3rd level domain to separate the applications would have been cleaner and all your routing code would have remained the same per domain.)

databyte
+1  A: 

Or you could use a named route and a view helper to define the url in a JavaScript var.

var autocomplete_path = <%= autocomplete_municipality_path %>;

Yeah, that's ugly.

(deploying your testing and production apps to separate domains (or subdomains) instead of separate dirs will eliminate these problems)

Jonathan Julian
the problem is they're both running as production and the same codebase. Just one was originally locked down to internal network access (/app_2) and then the second path was pointed to the old site (/app). Then when we went live, /app was redirected to the new code and /app_2 was open up to the public as well, mostly because our network team didn't want to have to rewrite a bunch of urls internally. So now we have two paths. I suppose I could force support of just /app... That would be a hell of a lot easier.
Lukas
Also thanks for the input. Both are ugly solutions, but I know it was going to be with how its running now. I was hoping there was something elegant. Maybe in Rails 3...
Lukas
actually this is closest to what I want, with a slight mod:`<%= javascript_tag "var uri = '#{request.request_uri.gsub("/", "")}';" -%>`which then lets me do`$("#municipality_name").autocomplete(uri + "munici...`forgot about the `request.request_uri` method.
Lukas