如何通过RubyonRails(地理位置、HTML5、javascript、RubyonRails)将javascript坐标存储到数据库中
如果可以的话,请帮忙 我一直在网上搜寻,试图找到一个关于如何将javascript变量从.js文件传递到控制器并在视图页面erb.html文件上显示的清晰解释。 到目前为止,这是我所拥有的一部分: .js文件: var lat=位置坐标纬度; var lon=位置坐标经度如何通过RubyonRails(地理位置、HTML5、javascript、RubyonRails)将javascript坐标存储到数据库中,javascript,ruby-on-rails,html,geolocation,coordinates,Javascript,Ruby On Rails,Html,Geolocation,Coordinates,如果可以的话,请帮忙 我一直在网上搜寻,试图找到一个关于如何将javascript变量从.js文件传递到控制器并在视图页面erb.html文件上显示的清晰解释。 到目前为止,这是我所拥有的一部分: .js文件: var lat=位置坐标纬度; var lon=位置坐标经度 $.ajax({ type: "GET", url: "/locations/show", data: { latitude: lat, longitude: lon } }); controller.rb文件 类位置控制
$.ajax({
type: "GET",
url: "/locations/show",
data: { latitude: lat, longitude: lon }
});
controller.rb文件
类位置控制器<应用程序控制器
def index
@lat = params[:latitude]
@long = params[:longitude]
//these print statements below display the collect variables in the console
print "this is lat: #{@lat}"
print "this is long: #{@long}"
end
view.erb.html
我很困惑!!!请帮忙!谢谢 这个问题对这个网站来说太宽泛了。选项包括更新提交的表单或通过ajax发送数据。这两种方法都应该易于在web上进行研究。
//the @lat & @long variables are now nil and don't display at all.
//but in the console they display the collect values.
this is lat: <%= @lat %>
this is long: <%= @long %>