0
votes

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?

1

1 Answers

1
votes

You should use the following instead:

<%= copy_foo_path() %>

And in your application config file add.

config.force_ssl = true

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.