codedog
codedog

Reputation: 2508

Returning to HTTP after Devise SSL controllers

I am trying to redirect requests to HTTP after Devise actions. I'm not sure if what I'm trying to do is the right/best way so I'm open to suggestion. Here's what I have and it's failing with a "redirect loop", which is understandable. Now I just need to figure out how to terminate the request after the redirect.

Is this worth pursuing, or is there a better way?

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :https_only_for_devise

  @@ssl_controllers = ['devise/registrations',
                        'devise/sessions']

  def https_only_for_devise
    if (@@ssl_controllers.index(params[:controller]) == nil)
      redirect_to :protocol => 'http://'
    end
  end
end

Upvotes: 0

Views: 327

Answers (1)

codedog
codedog

Reputation: 2508

And it worked! Changed the content of the method to:

  def https_only_for_devise
    if (@@ssl_controllers.index(params[:controller]) == nil && request.ssl?)
      redirect_to :protocol => 'http://'
    end
  end

Incredibly obvious now that I've thought about it...

Upvotes: 1

Related Questions