-
-
Save stammy/938501 to your computer and use it in GitHub Desktop.
Force SSL on Devise routes only, then redirect back
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
# Tell Devise to redirect after sign_in | |
def after_sign_in_path_for(resource_or_scope) | |
some_url(:protocol => 'http') | |
end | |
# Tell Devise to redirect after sign_out | |
def after_sign_out_path_for(resource_or_scope) | |
some_url(:protocol => 'http') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegistrationsController < Devise::RegistrationsController | |
private | |
# Tell Devise to redirect after account update | |
def after_update_path_for(resource) | |
me_url(:protocol => 'http') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JumpTask::Application.routes.draw do | |
# This class just makes the SSL constraint DRY | |
class SSL | |
def self.matches?(request) | |
# This way you don't need SSL for your development server | |
return true unless Rails.env.production? | |
request.ssl? | |
end | |
end | |
# Require SSL for Devise | |
constraints SSL do | |
devise_for :users, :controllers => { | |
:registrations => 'registrations' | |
} do { | |
# your custom Devise routes here | |
} | |
end | |
end | |
# Redirect to SSL from non-SSL so you don't get 404s | |
# Repeat for any custom Devise routes | |
match "/users(/*path)", :to => redirect { |_, request| | |
"https://" + request.host_with_port + request.fullpath } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment