我刚刚将 Geocoder gem 包含在我的应用程序中。一切都很完美,但我想知道我是否可以进一步使用 gem。
我的应用程序有用户,他们可以添加文章。目前我可以使用他们的 IP 地址
@article.ip_address = request.remote_ip
我一直在寻找可以帮助我将该 IP 地址转换为国家名称的 gem,但我找不到任何东西。由于我使用的是地理编码器,并且我意识到在他们的网站上他们会自动检测我的 IP、城市和国家/地区。我想知道如何将它实现到我的控制器。
def create
@article = Breeder.new(params[:breeder])
@article.user = current_user
@article.ip_address = request.remote_ip
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: 'Article was successfully created.' }
format.json { render json: @article, status: :created, location: @article }
else
format.html { render action: "new" }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
结尾
这个想法是检测不是来自英国的文章。