views:

148

answers:

2

New to Rails... here goes:

If I want my 'create' method to respond differently to an AJAX request than to a normal POST request, can I have the method detect which was used?

Or, is it better to use different methods for AJAX and non-AJAX requests?

Thanks for your input.

+1  A: 

request.xhr?

alamar
+1  A: 

Alternately, you can use a respond_to block:

def create
  # ...
  respond_to do |format|
    format.html # for standard requests
    format.js # for AJAX requests
    # other formats...
  end
end
Rufo Sanchez