Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过RubyonRails(地理位置、HTML5、javascript、RubyonRails)将javascript坐标存储到数据库中_Javascript_Ruby On Rails_Html_Geolocation_Coordinates - Fatal编程技术网

如何通过RubyonRails(地理位置、HTML5、javascript、RubyonRails)将javascript坐标存储到数据库中

如何通过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文件 类位置控制

如果可以的话,请帮忙

我一直在网上搜寻,试图找到一个关于如何将javascript变量从.js文件传递到控制器并在视图页面erb.html文件上显示的清晰解释。 到目前为止,这是我所拥有的一部分:

.js文件: var lat=位置坐标纬度; var lon=位置坐标经度

$.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 %>