Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This was a long time ago and I'm sure it can be improved, but back on some old version of rails I had this code in application controller. Not sure this is still valid for Rails 3, but it may be of some help:</p> <pre><code>private SECURE_ACTIONS = { :login =&gt; ["login", "login_customer", "remind_password", "add_customer", "add_or_login_customer"], :store =&gt; ["checkout", "save_order"], :order =&gt; ["show"] } # Called as a before_filter in controllers that have some https:// actions def require_ssl unless ENV['RAILS_ENV'] != 'production' or @request.ssl? redirect_to :protocol =&gt; 'https://', :action =&gt; action_name # we don't want to continue with the action, so return false from the filter return false end end def default_url_options(options) defaults = {} if USE_EXPLICIT_HOST_IN_ALL_LINKS # This will OVERRIDE only_path =&gt; true, not just set the default. options[:only_path] = false # Now set the default protocol appropriately: if actions = SECURE_ACTIONS[ (options[:controller] || controller_name).to_sym ] and actions.include? options[:action] defaults[:protocol] = 'https://' defaults[:host] = SECURE_SERVER if defined? SECURE_SERVER else defaults[:protocol] = 'http://' defaults[:host] = NON_SECURE_SERVER if defined? NON_SECURE_SERVER end end return defaults end </code></pre> <p>The <code>USE_EXPLICIT_HOST_IN_ALL_LINKS</code> was some global configuration option, but you can ignore this.</p> <p>In each controller that required https, I'd add <code>before_filter :require_ssl</code> and add that controller name and its methods to <code>SECURE_ACTIONS</code>. This probably can be improved by passing the action names to the before filter, or something.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload