Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 + devise: how do I make the email confirmation links use secure https (not http)

How to I tell Devise to use https (not http) for all the account confirmation and password reminder etc links?

[note: I'm not looking for a solution to redirect all http to https, I just need devise to ensure the links it creates use https]

Our rails 3 app uses devise, and the app runs fine under https, however, devise always uses http for the email confirmation and password links it emails to users.

In our environment files I tried changing:

config.action_mailer.default_url_options = { :host => "app1.mydomain.com" }  

to

 { :host => "https://app1.mydomain.com" }

but predictably devise creates links that look like http://https//app1.mydomain.com.... (eg, it prepends the :host settings with http:)

like image 424
jpw Avatar asked May 04 '11 03:05

jpw


2 Answers

default_url_options accepts the same hash parameters as url_for. So you should be able to do this:

config.action_mailer.default_url_options = { :protocol => 'https', :host => 'app1.mydomain.com' }
like image 66
aNoble Avatar answered Sep 30 '22 14:09

aNoble


To set the protocol but also a subdirectory :

config.action_mailer.default_url_options = {
        :host => "www.example.com",
        :protocol => 'https',
        :only_path => false,
        :script_name => "/app" #add this attribute if your app is deployed in a subdirectory
    }

Source

like image 32
Steve Lng C Avatar answered Sep 30 '22 14:09

Steve Lng C