来自 google 地理编码 api 的回滚事务错误 rails
rollback transaction error rails from google geocoding api
我正在尝试在我的 rails 应用程序中创建一个评论表单,但是当我点击提交按钮时,表单不能 submitted.When 我在终端中查找错误,我得到了这个错误。我搜索了错误但找不到任何解决方案。以前有人遇到过这个问题吗?:
Google API error: over query limit.
(0.1ms) rollback transaction
更新
我不仅收到 Google API 错误。有时我会收到此错误,而其他时候我只会收到回滚事务。
我是评论管理员:
class ReviewsController < ApplicationController
# check if logged in
before_action :check_login, except: [:index, :show]
def index
# this is our list page for our reviews
@price = params[:price]
@cuisine = params[:cuisine]
@location = params[:location]
# start with all the reviews
@reviews = Review.all
# filtering by price
if @price.present?
@reviews = @reviews.where(price: @price)
end
# filter by cuisine
if @cuisine.present?
@reviews = @reviews.where(cuisine: @cuisine)
end
# search near the location
if @location.present?
@reviews = @reviews.near(@location)
end
end
def new
# the form for adding a new review
@review = Review.new
end
def create
# take info from the form and add it to the model
@review = Review.new(form_params)
# and then associate it with a user
@review.user = @current_user
# we want to check if the model can be saved
# if it is, we're go the home page again
# if it isn't, show the new form
if @review.save
flash[:succces] = "Your review was posted!"
redirect_to root_path
else
# show the view for new.html.erb
render "new"
end
end
def show
# individual review page
@review = Review.find(params[:id])
end
def destroy
# find the individual review
@review = Review.find(params[:id])
# destroy if they have access
if @review.user == @current_user
@review.destroy
end
# redirect to the home page
redirect_to root_path
end
def edit
# find the individual review (to edit)
@review = Review.find(params[:id])
if @review.user != @current_user
redirect_to root_path
elsif @review.created_at < 4.hours.ago
redirect_to review_path(@review)
end
end
def update
# find the individual review
@review = Review.find(params[:id])
if @review.user != @current_user
redirect_to root_path
else
# update with the new info from the form
if @review.update(form_params)
# redirect somewhere new
redirect_to review_path(@review)
else
render "edit"
end
end
end
def form_params
params.require(:review).permit(:title, :restaurant, :body, :score,
:ambiance, :cuisine, :price, :address)
end
end
这是审核表单页面:
<%= simple_form_for @review do |f| %>
<%= f.input :title %>
<%= f.input :restaurant %>
<%= f.input :address %>
<%= f.input :body %>
<%= f.input :cuisine %>
<%= f.input :price %>
<%= f.input :score %>
<%= f.input :ambiance %>
<%= f.button :submit %>
<% end %>
审查模型
class Review < ApplicationRecord
# add an association that has a 1-to-many relationship
has_many :comments
has_many :bookmarks
# add an association to the user
belongs_to :user
geocoded_by :address
after_validation :geocode
validates :title, presence: true
validates :body, length: { minimum: 10 }
validates :score, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
validates :restaurant, presence: true
validates :address, presence: true
def to_param
id.to_s + "-" + title.parameterize
end
end
这是我的架构文件
create_table "reviews", force: :cascade do |t|
t.string "title"
t.text "body"
t.integer "score"
t.string "restaurant"
t.integer "price"
t.string "cuisine"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "phone_number"
t.string "ambiance"
t.text "address"
t.float "latitude"
t.float "longitude"
t.integer "user_id"
end
您可能已达到 Google API 配额。
在模型中,您有 geocoded_by ...
被 gem geocoder
使用,所以请看一下。
Google 有每秒限制和每天限制 link
你有两个问题:
- 您将超过 Google 的地理编码 API 配额,如错误消息 "over query limit"
所示
- 很可能因此,您的模型无法保存被回滚。地理编码 API 调用失败,不保存。
我会检查 Google API 控制台,看看你是否真的达到了他们的配额(如果你 运行 多次测试并且你在他们的免费层的服务)。如果您没有达到限制,请使用 Google API.
提交支持请求
我正在尝试在我的 rails 应用程序中创建一个评论表单,但是当我点击提交按钮时,表单不能 submitted.When 我在终端中查找错误,我得到了这个错误。我搜索了错误但找不到任何解决方案。以前有人遇到过这个问题吗?:
Google API error: over query limit.
(0.1ms) rollback transaction
更新
我不仅收到 Google API 错误。有时我会收到此错误,而其他时候我只会收到回滚事务。
我是评论管理员:
class ReviewsController < ApplicationController
# check if logged in
before_action :check_login, except: [:index, :show]
def index
# this is our list page for our reviews
@price = params[:price]
@cuisine = params[:cuisine]
@location = params[:location]
# start with all the reviews
@reviews = Review.all
# filtering by price
if @price.present?
@reviews = @reviews.where(price: @price)
end
# filter by cuisine
if @cuisine.present?
@reviews = @reviews.where(cuisine: @cuisine)
end
# search near the location
if @location.present?
@reviews = @reviews.near(@location)
end
end
def new
# the form for adding a new review
@review = Review.new
end
def create
# take info from the form and add it to the model
@review = Review.new(form_params)
# and then associate it with a user
@review.user = @current_user
# we want to check if the model can be saved
# if it is, we're go the home page again
# if it isn't, show the new form
if @review.save
flash[:succces] = "Your review was posted!"
redirect_to root_path
else
# show the view for new.html.erb
render "new"
end
end
def show
# individual review page
@review = Review.find(params[:id])
end
def destroy
# find the individual review
@review = Review.find(params[:id])
# destroy if they have access
if @review.user == @current_user
@review.destroy
end
# redirect to the home page
redirect_to root_path
end
def edit
# find the individual review (to edit)
@review = Review.find(params[:id])
if @review.user != @current_user
redirect_to root_path
elsif @review.created_at < 4.hours.ago
redirect_to review_path(@review)
end
end
def update
# find the individual review
@review = Review.find(params[:id])
if @review.user != @current_user
redirect_to root_path
else
# update with the new info from the form
if @review.update(form_params)
# redirect somewhere new
redirect_to review_path(@review)
else
render "edit"
end
end
end
def form_params
params.require(:review).permit(:title, :restaurant, :body, :score,
:ambiance, :cuisine, :price, :address)
end
end
这是审核表单页面:
<%= simple_form_for @review do |f| %>
<%= f.input :title %>
<%= f.input :restaurant %>
<%= f.input :address %>
<%= f.input :body %>
<%= f.input :cuisine %>
<%= f.input :price %>
<%= f.input :score %>
<%= f.input :ambiance %>
<%= f.button :submit %>
<% end %>
审查模型
class Review < ApplicationRecord
# add an association that has a 1-to-many relationship
has_many :comments
has_many :bookmarks
# add an association to the user
belongs_to :user
geocoded_by :address
after_validation :geocode
validates :title, presence: true
validates :body, length: { minimum: 10 }
validates :score, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
validates :restaurant, presence: true
validates :address, presence: true
def to_param
id.to_s + "-" + title.parameterize
end
end
这是我的架构文件
create_table "reviews", force: :cascade do |t|
t.string "title"
t.text "body"
t.integer "score"
t.string "restaurant"
t.integer "price"
t.string "cuisine"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "phone_number"
t.string "ambiance"
t.text "address"
t.float "latitude"
t.float "longitude"
t.integer "user_id"
end
您可能已达到 Google API 配额。
在模型中,您有 geocoded_by ...
被 gem geocoder
使用,所以请看一下。
Google 有每秒限制和每天限制 link
你有两个问题:
- 您将超过 Google 的地理编码 API 配额,如错误消息 "over query limit" 所示
- 很可能因此,您的模型无法保存被回滚。地理编码 API 调用失败,不保存。
我会检查 Google API 控制台,看看你是否真的达到了他们的配额(如果你 运行 多次测试并且你在他们的免费层的服务)。如果您没有达到限制,请使用 Google API.
提交支持请求