我正在开发中,并在我的rails 5应用程序上使用html5 geolocation:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setGeoCookie);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function setGeoCookie(position) {
我在Rails 4.1.1应用程序中使用:active_record_store作为session_store。我需要在我的应用程序中使会话cookie安全(仅限于HTTPS)。在开发环境中尝试了下面的代码,但没有为我工作。
MyApp::Application.config.session_store :session_store, key: '_session_id', secure: true
config.force_ssl = true: makes all cookie(s) as secure whcih is not requirement.
在应用程序配置
我成功地在JavaScript中设置了cookie:
var date = new Date();
date.setTime(date.getTime()+(1*24*60*60*1000)); //one day expiration date
var expires = "; expires="+date.toGMTString();
window.name = date.getTime();
document.cookie = "window_name="+window.name+expires+"; path=/";
然后在rails中我