Pouya
Pouya

Reputation: 65

How to find the request type?

I want to use a conditional to run a statement based on the type of request, but there is no way I can reproduce the error in production to see what the request is, but I was thinking of doing it this way:

def save_path
    if request.method == 'GET'
        # don't save the timeout path or else the user has no obvious way to log in
        session[:desired_path] = request.url unless request.url =~ /#{timeout_path}$/
    end
end

So, basically I want to say if the request's method is a GET request then this line should run but don't know if my conditional is setup correctly or not. Any assistance on this will be greatly appreciated.

Upvotes: 0

Views: 294

Answers (1)

Sara Fuerst
Sara Fuerst

Reputation: 6068

You can check using a built in method:

request.get?

This answer to a similar question may be helpful for further info:

https://stackoverflow.com/a/4023538/3435610

Upvotes: 2

Related Questions