In a Rails controller, I can set a cookie like this:
cookies[:foo] = \"bar\"
And specify that the \"secure\" (https-only) flag be on like this:
You should look at the rack-ssl-enforcer gem. I was just looking for a clean answer to this and it solves the problem independent of which version of Rails you're on, plus it's extremely configurable.
# session only available over HTTPS
ActionController::Base.session_options[:secure] = true