I am using jquery ajax call and in controller action i want to redirect some action but when
i use redirect_to “/some_action”. Then it did not redirect to my desired action please give
any useful suggestions.
<%= link_to "javascript:;" ,:onclick => "admin_fun"%>
my jquery ajax call is
function admin_fun() {
if (confirm("Are you sure you want to add?")) {
var container = $("#trunk_detail");
$.ajax({
url:'/accounting/add_rule',
type:'get',
dataType:'html',
processData:false,
success:function (data) {
container.html(data);
}
});
}
}
my controller code is
def add_rule
# do somthing
redirect_to "/accounting/index_report"
render :text => "ok"
end
This line will not give you the desired results because you can redirect or render multiple times.rather than you omit this line from controller
redirect_to “/accounting/index_report”
and in jquery ajax call on success response you can redirect to your desired action like
if (confirm(“Are you sure you want to add?”)) {
}
}
And enjoying……..