Skip to content

Instantly share code, notes, and snippets.

@BlackFoks
Forked from a-chernykh/application_controller.rb
Created September 4, 2013 02:32
Show Gist options
  • Save BlackFoks/6432155 to your computer and use it in GitHub Desktop.
Save BlackFoks/6432155 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
before_filter :ensure_proper_protocol
protected
def ssl_allowed_action?
(params[:controller] == 'users/sessions' && ['new', 'create'].include?(params[:action])) ||
(params[:controller] == 'users/registrations' && ['new', 'create', 'edit', 'update'].include?(params[:action])) ||
(params[:controller] == 'users/omniauth_callbacks')
end
def ensure_proper_protocol
if request.ssl? && !ssl_allowed_action?
redirect_to "http://" + request.host + request.fullpath
end
end
def after_sign_in_path_for(resource_or_scope)
root_url(:protocol => 'http')
end
def after_sign_out_path_for(resource_or_scope)
root_url(:protocol => 'http')
end
end
class Users::RegistrationsController < Devise::RegistrationsController
force_ssl :only => [:new, :create, :edit, :update]
protected
def after_inactive_sign_up_path_for(resource)
root_url(:protocol => 'http')
end
def after_sign_up_path_for(resource)
root_url(:protocol => 'http')
end
def after_update_path_for(resource)
edit_user_registration_url(:protocol => 'http')
end
end
class Users::SessionsController < Devise::SessionsController
force_ssl :only => [:new, :create]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment