【问题标题】:Heroku Rails Log Error Message on text field: ERROR invalid body size文本字段上的 Heroku Rails 日志错误消息:错误无效的正文大小
【发布时间】:2015-02-24 22:01:19
【问题描述】:

我正在使用 Heroku Postgres :: Onyx 的爱好层运行托管在 Heroku 上的 rails 4.0.2 应用程序。我的日志文件中有一个奇怪的错误,并且记录无法保存。我无法重现错误。

2014-05-23T05:28:33.443728+00:00 app[web.1]: [2014-05-23 05:28:33] ERROR invalid body size.

这个错误奇怪的原因是我的应用程序中唯一的正文字段是一个文本字段。

以下是相关架构:

create_table "invitation_templates", force: true do |t|

  t.integer  "business_id"
  t.string   "subject"
  t.text     "body"
  t.datetime "created_at"
  t.datetime "updated_at"
end

这是我的模型(顺便说一下,其中不包含验证):

class InvitationTemplate < ActiveRecord::Base

  belongs_to :business

end

这是完整的控制器:

定义创建

# @user set by correct_user

# @business set by correct_user   

@invite = Invite.new(invite_params)

if @invite.valid?
  invtemp = InvitationTemplate.find_or_create_by(business_id: @business.id)
  invtemp.subject = @invite.subject
  invtemp.body = @invite.message
  invtemp.save    # <--- This is the only line that I can think of as having thrown the error

  if invite_params[:image_file].present?
    uploaded_io = invite_params[:image_file]
    @invite.image_id = Image.add_or_update( @invite.image_id, uploaded_io, "invites" )
  end # if params[:image_file].present?

  inviter = ManInvite.new
  res = inviter.sendInvitation(@invite, @business)

  if res
    flash[:notice] = "We sent your message(s).  You will recieve an email when a new testimonial has been submitted."
  else
    flash[:error] = "We saved your message(s).  But had a problem sending.  Please contact support with this information: #{@invite.status} #{@invite.audit_id}"
  end

  if params[:send_another]
    redirect_to( new_business_invite_path(@business) )
  else
    redirect_to(  business_dashboard_index_path(current_user.businesses.first()) )
  end

else
  render 'new'
end

结束

我认为文本字段不会引发大小错误。对此错误的原因/来源的任何想法将不胜感激。

【问题讨论】:

  • 你做了什么来尝试在本地复制它?你的控制器代码是什么样的?
  • 就娱乐而言,我已经用无数不同的身体值执行了这段代码。包括那些一开始没有保存并且它们都正确保存的那个(我有一个失败值的副本,因为它被传递给 ManInvite.sendInvitation,它将值写入审计日志)。

标签: ruby-on-rails ruby postgresql heroku


【解决方案1】:

我在尝试做一个简单的获取时偶然发现了同样的错误。 您看到的错误消息与您有一个名为 body 的属性(至少基于我的情况)这一事实无关。 我的问题与错误的 http get 请求有关。 我正在使用 Alamofire(iOS 库)发出 GET 请求并将编码设置为 JSON。这是一个无效的请求,被 rails 拒绝了。

如果您查看日志,您可能不会看到日志行,例如 Started POST "/invitations ... 这意味着该请求甚至没有被 Rails 解析。

检查您是如何提出请求的,并确保那里没有错误。

编辑:

我会更直接一点:问题与您提出请求的方式有关,而不是与您拥有 body 属性这一事实有关。

  1. 如果您是通过浏览器发出请求,请通过单击 URL 检查它是否与上一条评论中报告的错误无关。
  2. 如果您自己构建请求,请使用第三方库检查请求是否正确构建。

我建议您尝试使用 Postman(chrome 扩展)对您的通话进行快速测试。我已经起草了quick rails app 来尝试您的方案。 在下图中检查如何使用邮递员向您的服务器发出请求:postman post request

另外,我已经在 heroku 中部署了这个草稿应用程序(floating-sands-5859 是应用程序的名称)

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post
  • @cpburnz 正如我在更新的答案中提到的那样,我非常确信作者面临的问题与他的模型上有一个 body 属性这一事实无关,而是一个在构建他的请求时遇到问题,我以我以前的经验为例。我无法进一步澄清他,因为我还不知道他是如何提出要求的。无论如何,我最初的答案没有错,并且在所提供信息的范围内有所帮助(可能是模糊的)
【解决方案2】:

当 HTTP POST 标头中的 Content-length 值错误时,我遇到了类似的错误。 (我有一个 Arduino 兼容设备发布到 rails 4.1 网络服务器)

显然旧版本的 Firefox 存在此问题,因此可能是您的浏览器存在问题。 https://bugzilla.mozilla.org/show_bug.cgi?id=619683

我能够通过修复我的嵌入式设备程序中的错误来修复错误,但我怀疑你也能做到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-09
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    相关资源
    最近更新 更多