Ruby on rails “如何进行地理编码”;“ip”中的当前“用户”签名;登录后
因此,目前我有一个应用程序托管在heroku上 我正在使用Desive gem进行所有用户身份验证 我希望用户能够检查他们在地图上的当前位置,为此,我使用geocoder gem 但是,在登录用户后,ip已注册,但其经度和纬度值不会更改并保持为“零” 如果我进入rails控制台,给当前的注册ip一个不同的值,那么它就开始工作了 这就是我的User.rb文件目前的样子:Ruby on rails “如何进行地理编码”;“ip”中的当前“用户”签名;登录后,ruby-on-rails,devise,gmaps4rails,rails-geocoder,Ruby On Rails,Devise,Gmaps4rails,Rails Geocoder,因此,目前我有一个应用程序托管在heroku上 我正在使用Desive gem进行所有用户身份验证 我希望用户能够检查他们在地图上的当前位置,为此,我使用geocoder gem 但是,在登录用户后,ip已注册,但其经度和纬度值不会更改并保持为“零” 如果我进入rails控制台,给当前的注册ip一个不同的值,那么它就开始工作了 这就是我的User.rb文件目前的样子: class User < ApplicationRecord attr_accessor :firstname,
class User < ApplicationRecord
attr_accessor :firstname, :lastname
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable,
:rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook , :google_oauth2]
geocoded_by :current_sign_in_ip
after_validation :geocode
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.firstname = auth.info.firstname
end
end
end
class用户[:facebook,:google\u oauth2]
地理编码者:ip中的当前符号
验证后:地理编码
定义自授权(授权)
其中(provider:auth.provider,uid:auth.uid)。首先|
user.provider=auth.provider
user.uid=auth.uid
user.email=auth.info.email
user.password=design.friendly_令牌[0,20]
user.firstname=auth.info.firstname
结束
结束
结束
这就是我目前显示地图的视图:
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<% if user_signed_in? %>
<div style="'width: 800px">
<div id = "map" style = "width: 800px; height: 400px;"></div>
</div>
<script type="application/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": (<%= current_user.latitude %>),
"lng": (<%= current_user.longitude %>),
"picture": {
"url":
"https://i.pinimg.com/736x/4e/e8/fb/4ee8fbf4312a171c9e344abb30c65e21.jpg",
"width": 32,
"height": 32
},
"infowindow": "hello!"
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
<% else %>
<% end %>
Home#索引
在app/views/home/index.html.erb中查找我
handler=Gmaps.build('Google');
buildMap({provider:{},internal:{id:'map'}},function(){
markers=handler.addMarkers([
{
“lat”:(),
“液化天然气”:,
“图片”:{
“url”:
"https://i.pinimg.com/736x/4e/e8/fb/4ee8fbf4312a171c9e344abb30c65e21.jpg",
“宽度”:32,
“高度”:32
},
“信息窗口”:“你好!”
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
所以我的问题是evne虽然“当前符号”有一个值,但用户在该点的经度和纬度没有被地理编码
如果我让用户在登录时输入他们当前的IP地址,它就会起作用。我检查了Geocoder gem的文档,这似乎是配置它的正确方法。我认为您需要调试after_验证方法,通过添加一个不同的after_验证来测试geocode方法,类似于:
after_validation :geocode_test
def geocode_test
binding.pry # or debug if you don't use pry
geocode
end
它不能正常工作应该是有原因的。它可能也在您的服务器日志中,您是否检查了错误