The Hitchhiker’s Guide to Ruby On Rails Galaxy

Records of my voyage through RoR Galaxy

How to determine whether a request was Ajax or not?

Posted by arjunghosh on April 18, 2008

This is something I wanted to remind self also:
Never do the following:

if request.xhr?
render(:update) { |page| ... }
else
redirect_to(...)
end

And instead do the following:

respond_to do |format|
format.html { redirect_to(...) }
format.js { render(:update) { |page| ... } }
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: