Hi,
I have a Rails web app working, and I am now working on a mobile app
using Phonegap. Phonegap works only with javascript/html, so I make Ajax
request to my web app and render things if the request is make from
Ajax.
This is what I have in my controller action
if request.xhr?
render :controller => ‘user_session’, :action => ‘new’, :layout =>
false params[:id].present?
render :controller => ‘user’, :action => ‘new’, :layout => false if
params[:id].blank?
else
redirect_to login_path if params[:id].present?
redirect_to register_path if params[:id].blank?
end
My javascript
HOST = ‘localhost:3000’;
new Ajax.Request(HOST,
{
method: ‘get’,
onComplete: function(transport){alert(‘kikoo’);}
}
);
I have two problem with this code, the first one is that it doesn’t
recognize that I am making an Ajax request because it is going in the
else condition. And the second problem is that if I remove the if
statement I have rendering problem, it tries to render the new action
from the current controller.
I have two problem with this code, the first one is that it doesn’t
recognize that I am making an Ajax request because it is going in the
else condition
Have you looked in the log to see what the request is? Have you
broken in to the code using ruby-debug for example to check the value
of request.xhr?
. And the second problem is that if I remove the if
statement I have rendering problem, it tries to render the new action
from the current controller.
I have two problem with this code, the first one is that it doesn’t
recognize that I am making an Ajax request because it is going in the
else condition
Have you looked in the log to see what the request is? Have you
broken in to the code using ruby-debug for example to check the value
of request.xhr?
. And the second problem is that if I remove the if
statement I have rendering problem, it tries to render the new action
from the current controller.
Again does the log show anything useful?
Colin
Yes I have check the log and it doesn’t help. I logged each step and I
confirm that it is not an Ajax request…
Yes I have check the log and it doesn’t help. I logged each step and I
confirm that it is not an Ajax request…
Rails looks at the X-Requested-With header to see if a request was an
ajax one. Prototype, jquery etc. set this header, but if phonegap
doesn’t then rails won’t consider it to be an ajax request
Rails looks at the X-Requested-With header to see if a request was an
ajax one. Prototype, jquery etc. set this header, but if phonegap
doesn’t then rails won’t consider it to be an ajax request
Fred
I’m not making the Ajax query with phonegap but with prototype
Yes I have check the log and it doesn’t help. I logged each step and I
confirm that it is not an Ajax request…
Rails looks at the X-Requested-With header to see if a request was an
ajax one. Prototype, jquery etc. set this header, but if phonegap
doesn’t then rails won’t consider it to be an ajax request
Fred
X-Requested-With header looks like this when I execute the Ajac in
firebug:
Access-Control-Request-He… x-prototype-version,x-requested-with
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.