jQuery AJAX request with relative URLs in Rails
I have a Rails application that is being deployed to JBoss under a subfolder (application context root). My ajax requests work correctly when I run under development environment or when I make a GET request to the 'new' action. When I submit my form an开发者_JS百科d do a 'render' back to the 'new' action after save fails (errors found), the ajax call refers back to the root and does not include the subfolder/context root. I apologize upfront as its hard to articulate exactly what I'm needing and the current behavior.
What I am looking for is the ajax request url to go to following.
On dev system with no subfolder (GET / and after render):
http://localhost:3000/ach/routing_number_search...
On JBOSS with subfolder (GET):
http://localhost:8080/EntryTool/ach/routing_number_search...
AFTER RENDER (WRONG) <-- Need to change to be like ajax url in GET
http://localhost:8080/ach/routing_number_search...
Javascript
$.post('../ach/routing_number_search', {
bank_id: idField.val(),
authenticity_token: $("input:[name=authenticity_token]").val(),
utf8: $("input:[name=utf8]").val()
}, function(data){
myField.val(data.bank.aba);
}, "json");
Rails Controller
def create
if @entry.errors.empty?
flash[:notice] = 'Entry Successfully Submitted.'
redirect_to(:action => 'new')
else
session[:entry] = @entry
render(:action => 'new')
end
end
精彩评论