Geocoder 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
終わり
アイデアは、英国以外の記事を検出することです。