开发者

jQuery with Rails when deployed to multiple subURIs

开发者 https://www.devze.com 2022-12-19 12:56 出处:网络
Hey. So I have a Rails app that\'s getting deployed to a production machine that serves it via Apache/Passenger to two subURIs.

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:

$("#mun开发者_StackOverflow中文版icipality_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?


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)


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消