A D Vishnu Prasad

Director of Cloud Engineering @ Team8Solutions, Freelancer

Find Type of the Request in Controller

Is there any way to find the type of request in controller ?

Yes.

What we do in routes.rb is , define the type of request to particular action.

But, what If we want to find out the type of request in controller .

1
2
3
4
5
6
7
if request.get?
   logger.info "Request is GET"
elsif request.post?
   logger.info "Request is POST"
elsif request.xhr?
   logger.info "Request is AJAX"
end