In my routes.rb I have a custom path defined:
match "foo/copy" => "foo#copy", :via => [ :post ], :as => "copy_foo"
I have an initializer in my config/initializers directory named https_by_default.rb, which contains one line:
Rails.application.routes.default_url_options[:protocol] = 'https'
If I run rails console and type Rails.application.routes.default_url_options, it returns {:protocol => 'https} as expected.
But in my view where I am using the generated custom path _url helper, it doesn’t generate the URL with https. <%= copy_foo_url() %> in the ERB returns http://localhost:3000/foo/copy.
What am I missing in order to get my named routes helpers to respect default_url_options?
You should use the following instead:
And in your application config file add.
This enables ssl on all your Rails environments. If you want to enable ssl on your production environment only, then just add the line to your production config file.