How do I get the "remote_form_for" usage detection method?

New to Rails ... here goes:

If I want my "create" method to respond differently to an AJAX request than a regular POST request, can I determine the method that was used?

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

Thanks for your input.

0


a source to share


2 answers


Alternatively, you can use the response_to block:



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

      

0


a source


request.xhr?



+3


a source







All Articles